IDEA創建webservice項目 由於我本地下載不了遠程的jar包,手動導入jar和配置依賴axis-1.4
axis-1.4.jar解壓后添加到源文件 有一部分servlet需要依賴

搜索了很多不知具體是那些jar我就導入了這些jar

實現比較簡單
1.定義接口 添加 @webservice 方法@webmethod
2.實現類
3.發布
Endpoint.publish(addrs,new testwebserviceImpl());發布制定的方法和發布地址
/** * Created by Administrator on 2019/4/3/0003. */ public class demo { public static void main(String[] args) { String addrs="http://localhost:8080/test/webservice"; Endpoint.publish(addrs,new testwebserviceImpl()); System.err.println("發布"); } }
package example; import javax.jws.WebMethod; import javax.jws.WebService; /** * Created by Administrator on 2019/4/3/0003. */ @WebService public interface testwebservice { @WebMethod String sayhi(String name); }
package example; import javax.jws.WebService; /** * Created by Administrator on 2019/4/3/0003. */ @WebService public class testwebserviceImpl implements testwebservice { @Override public String sayhi(String name) { System.err.println("ok"); String a=name+"-------------"; return a; } }
發布地址+?wsdl 為xml格式數據
http://localhost:8080/test/webservice?wsdl

新建一個webservice客戶端
首先我們先創建一個client客戶端的項目,然后我們通過Win+R組合鍵調出cmd,在cmd中輸入wsimport -s 我們這個項目的src路徑 -keep 我們發布的webservice地址
wsimport -s F:\clientwebs -keep http://localhost:8080/test/webservice?wsdl
解析xml生成實體類

mian方法調用發布接口
package example;/** * Created by Administrator on 2019/4/3/0003. */ public class HelloWorld { public static void main(String[] args) { TestwebserviceImplService testwebserviceImplService = new TestwebserviceImplService(); TestwebserviceImpl wsImpl = testwebserviceImplService.getTestwebserviceImplPort(); String nmsl = wsImpl.sayhi("nmsl"); System.err.println(nmsl); } }

源碼:
鏈接:https://pan.baidu.com/s/16gRbYxH-AmKXQzsvnULZBg
提取碼:rgyh
