之前寫過一篇springboot對接webservice的文章https://blog.csdn.net/qq_15058425/article/details/103732273,發現我把對接webservice搞複雜了,而且我最近在對接新的webservice接口時,發現用上面這篇文章生成的代碼及利用eclipse生成的代碼是不一樣的。而且利用eclipse生成的話更簡單方便,如下我們開始嘗試一下,例子還是上篇文章的查詢天氣的接口:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl
1、現在eclipse中創建一個maven項目
2、利用eclipse生成代碼
最後點擊Finish即可
可以看到生成的代碼:
3、寫一個測試類測試一下:
public class Frist {
public static void main(String[] args) {
WeatherWebServiceSoapProxy service=new WeatherWebServiceSoapProxy();
try {
String[] provinces=service.getSupportProvince();
for(String province:provinces) {
System.out.println("支持的省份=="+province);
}
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
輸出結果:
果然很簡單吧
如下是pom配置,這個在webservice整合到項目的時候有用
<dependency> <groupId>org.apache.axis</groupId> <artifactId>axis-jaxrpc</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>org.apache.axis</groupId> <artifactId>axis</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>wsdl4j</groupId> <artifactId>wsdl4j</artifactId> <version>1.6.3</version> </dependency> <dependency> <groupId>commons-discovery</groupId> <artifactId>commons-discovery</artifactId> <version>0.5</version> </dependency>