关于WebService
一 查找免费的web service
天气预报Web服务,数据来源于中国气象局
Endpoint : http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl
IP地址来源搜索 WEB 服务(是目前最完整的IP地址数据)
Endpoint : http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl
中国邮政编码 <-> 地址信息双向查询/搜索 WEB 服务
Endpoint : http://www.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/ChinaZipSearchWebService.asmx?wsdl
验证码图片 WEB 服务 支持中文、字母、数字 图像和多媒体
Endpoint : http://www.webxml.com.cn/WebServices/ValidateCodeWebService.asmx
Disco : http://www.webxml.com.cn/WebServices/ValidateCodeWebService.asmx?disco
WSDL : http://www.webxml.com.cn/WebServices/ValidateCodeWebService.asmx?wsdl
还有好多接口网站给个链接:https://blog.csdn.net/w405722907/article/details/73741898
1.1获取天气预报的web service
http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
拼接 ?wsdl wsdl是一种描述web service的一种格式 连接:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl
1.2创建一个java项目 在src目录下打开dos窗口输入:wsimport -keep http://www.webxml.com.cn/WebServices/WeatherWebService.asmx?wsdl
报错:解决办法 将wsdl文件保存到本地,并修改文件内容(修改wsdl文档的部分内容:将 <s:element ref="s:schema" /><s:any /> 替换成 <s:any minOccurs="2" maxOccurs="2"/>)
1.3打开dos窗口输入:wsimport -keep 本地路径+文件名.wsdl
1.4刷新客户端,代码生成完毕
1.5编写test用例:
package cn.com.test;
import java.util.List;
import cn.com.webxml.ArrayOfString;
import cn.com.webxml.WeatherWebService;
import cn.com.webxml.WeatherWebServiceSoap;
public class test {
public static void main(String[] args) {
//创建一个weatherWS工厂
WeatherWebService fact = new WeatherWebService();
//根据工厂创建一个WeatherWebServiceSoap
WeatherWebServiceSoap ws =fact.getWeatherWebServiceSoap();
//调用getWeatherbyCityName
ArrayOfString weatherInfo=ws.getWeatherbyCityName("南宁");
List<String> lstWeatherInfo = weatherInfo.getString();
//遍历
for (String string : lstWeatherInfo){
System.out.println(string);
System.out.println("-----------------------------");
}
}
}
执行结果:
广西 ----------------------------- 南宁 ----------------------------- 59431 ----------------------------- 59431.jpg ----------------------------- 2019/8/27 22:23:12 ----------------------------- 25℃/32℃ ----------------------------- 8月22日 阵雨 ----------------------------- 东南风小于3级 ----------------------------- 3.gif ----------------------------- 3.gif ----------------------------- 今日天气实况:气温:25℃;风向/风力:东北风 2级;湿度:100%;紫外线强度:中等。空气质量:良。 ----------------------------- 紫外线指数:中等,涂擦SPF大于15、PA+防晒护肤品。 健臻·血糖指数:易波动,气温多变,血糖易波动,请注意监测。 穿衣指数:炎热,建议穿短衫、短裤等清凉夏季服装。 洗车指数:不宜,有雨,雨水和泥水会弄脏爱车。 空气污染指数:良,气象条件有利于空气污染物扩散。

浙公网安备 33010602011771号