使用eclipse客户端生成WebService客户端进行接口调用:
new ->
Web Service Client ->
输入服务地址,例如:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl ->
next查看生成项目路径 ->
finish
此接口生成的项目文件如图:
接口调用:
URL url = new URL("http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");
WeatherWebServiceLocator service = new WeatherWebServiceLocator();
WeatherWebServiceSoapStub stub = new WeatherWebServiceSoapStub(url, service);
String[] city = stub.getSupportCity("ALL");
String[] weatherbyCityName = stub.getWeatherbyCityName("上海");
System.out.println(Arrays.toString(weatherbyCityName));
结果:
[直辖市, 上海, 16℃/27℃, 4月16日 多云转中雨, 南风4-5级, 1.gif, 8.gif, 今日天气实况:气温:25℃;风向/风力:东北风 1级;湿度:32%;紫外线强度:中等。空气质量:良。, 紫外线指数:中等,涂擦SPF大于15、PA+防晒护肤品。
健臻·血糖指数:易波动,风力较大,血糖易波动,注意监测。
穿衣指数:舒适,建议穿长袖衬衫单裤等服装。
洗车指数:不宜,有雨,雨水和泥水会弄脏爱车。
空气污染指数:良,气象条件有利于空气污染物扩散。
, 15℃/22℃, 4月17日 小雨转阴, 西风3-4级转西北风小于3级, 7.gif, 2.gif, 15℃/20℃, 4月18日 小雨转中雨, 东风3-4级, 7.gif, 8.gif, 上海简称:沪,...。]
maven项目引入依赖:
<!-- webservices -->
<!-- https://mvnrepository.com/artifact/org.apache.axis/axis -->
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/axis/axis-jaxrpc -->
<dependency>
<groupId>axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.xml.soap/saaj-api -->
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
<version>1.3.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/wsdl4j/wsdl4j -->
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-discovery/commons-discovery -->
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
JDK自己内置了一个wsimport工具
wsimport -encoding utf-8 -s d:/ws -p com.app.webservice.client -keep http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl
-keep:是否生成java源文件
-d:指定输出目录,必须是存在的目录
-s:指定源代码输出目录
-p:以package的形式生成文件
-verbose:在控制台显示输出信息