1:建一个webservice接口 自定义一个方法 @WebService public interface IPushInfo {
@WebMethod public String pushInfo(@WebParam(name ="data") String data);}
2:实现接口,实现方法 @WebService(endpointInterface=”crm_lhx.webservice.IPushInfo”) public class PushInfoImp implements IPushInfo {
@Override public String pushInfo(String data) { System.out.println("webservice 入参...." + data); return "info..." + data; } public static void main(String[] args) { //发布webservice Endpoint.publish("http://192.168.2.70/pushInfo",new PushInfoImp()); }}
3:发布接口 路径自定义
public static void main(String[] args) { //发布webservice Endpoint.publish("http://192.168.2.77/pushInfo",new PushInfoImp()); }运行后再浏览器输入地址校验 http://192.168.2.77/pushInfo?wsdl
1:用wsimport 命令生成代码 cmd运行 然后切换到指定的目录,这样生成的java文件也在该目录下面
执行命令 wsimport -keep -p com.demo.client http://192.168.2.77/pushInfo?wsdl
然后把生成的java文件copy到对应的程序中 //客户端代码
public class PushInfoClient {
public static void main(String[] args) { // PushInfoImpService 这个是根据 wsdl 用命令自动生成的文件,w PushInfoImpService server = new PushInfoImpService(); String string = server.getPushInfoImpPort().pushInfo("hello!"); System.out.println(string); }}