webservice 教程学习系列(七)——编写天气预报和手机号码归属地的webservice
1.编写天气预报的webservice
首先我们在http://www.webxml.com.cn/zh_cn/index.aspx里面找到天气预报的url
然后找到获取地区天气的接口方法:
看到方法函数
得到URL链接:
然后在浏览器中输入该URL:http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl
得到约束文本信息:
然后新建java工程,在src下的dos窗口中解析url链接
会发现解析出错:
原因是因为该webservice的server端是使用.net开发的,而我们是使用java的clien端调用的。
所以解决方法是,将该约束文件保存为本地的WSDL文本文件,然后将其中所有的<s:element ref="s:schema" /> <s:any />替换成<s:any minOccurs="2" maxOccurs="2"/>即可。
贴一下report.wsdl的源码
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://WebXml.com.cn/"xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://WebXml.com.cn/"xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><ahref="http://www.webxml.com.cn/"target="_blank">WebXml.com.cn</a><strong>2400多个城市天气预报Web服务</strong>,包含2300个以上中国城市和100个以上国外城市天气预报数据。数据每2.5小时左右自动更新一次,准确可靠。<br/>使用本站 WEB 服务请注明或链接本站:<a href="http://www.webxml.com.cn/"target="_blank">http://www.webxml.com.cn/</a> 感谢大家的支持!<br/><br /><img alt="PDF" title="PDF file"src="http://www.webxml.com.cn/images/icon/pdf.gif"style="vertical-align: middle;" /> <ahref="http://www.webxml.com.cn/files/WeatherWsHelp.pdf"target="_blank">接口帮助文档</a> &nbsp;&nbsp;&nbsp;<img alt="ZIP" title="ZIP file"src="http://www.webxml.com.cn/images/icon/zip.gif"style="vertical-align: middle;" /> <ahref="http://www.webxml.com.cn/files/about_city.zip">部分城市介绍和气候背景</a>&nbsp;&nbsp;&nbsp; <img alt="ZIP" title="ZIP file"src="http://www.webxml.com.cn/images/icon/zip.gif"style="vertical-align: middle;" /> <ahref="http://www.webxml.com.cn/files/city_photo.zip">部分城市图片</a>&nbsp;&nbsp;&nbsp; <img alt="HTML" title="HTML file"src="http://www.webxml.com.cn/images/icon/html.gif"style="vertical-align: middle;" /> <ahref="http://www.webxml.com.cn/zh_cn/weather_icon.aspx"target="_blank">天气现象和图例</a><br />&nbsp;</wsdl:documentation><wsdl:types><s:schema elementFormDefault="qualified" targetNamespace="http://WebXml.com.cn/"><s:element name="getRegionDataset"><s:complexType /></s:element><s:element name="getRegionDatasetResponse"><s:complexType><s:sequence><s:element minOccurs="0" maxOccurs="1"name="getRegionDatasetResult"><s:complexType><s:sequence><s:any minOccurs="2" maxOccurs="2"/></s:sequence></s:complexType></s:element></s:sequence></s:complexType></s:element><s:element name="getRegionProvince"><s:complexType /></s:element><s:element name="getRegionProvinceResponse"><s:complexType><s:sequence><s:element minOccurs="0" maxOccurs="1"name="getRegionProvinceResult" type="tns:ArrayOfString" /></s:sequence></s:complexType></s:element><s:complexType name="ArrayOfString"><s:sequence><s:element minOccurs="0" maxOccurs="unbounded" name="string"nillable="true" type="s:string" /></s:sequence></s:complexType><s:element name="getRegionCountry"><s:complexType /></s:element><s:element name="getRegionCountryResponse"><s:complexType><s:sequence><s:element minOccurs="0" maxOccurs="1"name="getRegionCountryResult" type="tns:ArrayOfString" /></s:sequence></s:complexType></s:element><s:element name="getSupportCityDataset"><s:complexType><s:sequence><s:element minOccurs="0" maxOccurs="1" name="theRegionCode"type="s:string" /></s:sequence></s:complexType></s:element><s:element name="getSupportCityDatasetResponse"><s:complexType><s:sequence><s:element minOccurs="0" maxOccurs="1"name="getSupportCityDatasetResult"><s:complexType><s:sequence><s:any minOccurs="2" maxOccurs="2"/></s:sequence></s:complexType></s:element></s:sequence></s:complexType></s:element><s:element name="getSupportCityString"><s:complexType><s:sequence><s:element minOccurs="0" maxOccurs="1" name="theRegionCode"type="s:string" /></s:sequence></s:complexType></s:element><s:element name="getSupportCityStringResponse"><s:complexType><s:sequence><s:element minOccurs="0" maxOccurs="1"name="getSupportCityStringResult" type="tns:ArrayOfString" /></s:sequence></s:complexType></s:element><s:element name="getWeather"><s:complexType><s:sequence><s:element minOccurs="0" maxOccurs="1" name="theCityCode"type="s:string" /><s:element minOccurs="0" maxOccurs="1" name="theUserID"type="s:string" /></s:sequence></s:complexType></s:element><s:element name="getWeatherResponse"><s:complexType><s:sequence><s:element minOccurs="0" maxOccurs="1" name="getWeatherResult"type="tns:ArrayOfString" /></s:sequence></s:complexType></s:element><s:element name="DataSet" nillable="true"><s:complexType><s:sequence><s:any minOccurs="2" maxOccurs="2"/></s:sequence></s:complexType></s:element><s:element name="ArrayOfString" nillable="true"type="tns:ArrayOfString" /></s:schema></wsdl:types><wsdl:message name="getRegionDatasetSoapIn"><wsdl:part name="parameters" element="tns:getRegionDataset" /></wsdl:message><wsdl:message name="getRegionDatasetSoapOut"><wsdl:part name="parameters" element="tns:getRegionDatasetResponse" /></wsdl:message><wsdl:message name="getRegionProvinceSoapIn"><wsdl:part name="parameters" element="tns:getRegionProvince" /></wsdl:message><wsdl:message name="getRegionProvinceSoapOut"><wsdl:part name="parameters" element="tns:getRegionProvinceResponse" /></wsdl:message><wsdl:message name="getRegionCountrySoapIn"><wsdl:part name="parameters" element="tns:getRegionCountry" /></wsdl:message><wsdl:message name="getRegionCountrySoapOut"><wsdl:part name="parameters" element="tns:getRegionCountryResponse" /></wsdl:message><wsdl:message name="getSupportCityDatasetSoapIn"><wsdl:part name="parameters" element="tns:getSupportCityDataset" /></wsdl:message><wsdl:message name="getSupportCityDatasetSoapOut"><wsdl:part name="parameters" element="tns:getSupportCityDatasetResponse" /></wsdl:message><wsdl:message name="getSupportCityStringSoapIn"><wsdl:part name="parameters" element="tns:getSupportCityString" /></wsdl:message><wsdl:message name="getSupportCityStringSoapOut"><wsdl:part name="parameters" element="tns:getSupportCityStringResponse" /></wsdl:message><wsdl:message name="getWeatherSoapIn"><wsdl:part name="parameters" element="tns:getWeather" /></wsdl:message><wsdl:message name="getWeatherSoapOut"><wsdl:part name="parameters" element="tns:getWeatherResponse" /></wsdl:message><wsdl:message name="getRegionDatasetHttpGetIn" /><wsdl:message name="getRegionDatasetHttpGetOut"><wsdl:part name="Body" element="tns:DataSet" /></wsdl:message><wsdl:message name="getRegionProvinceHttpGetIn" /><wsdl:message name="getRegionProvinceHttpGetOut"><wsdl:part name="Body" element="tns:ArrayOfString" /></wsdl:message><wsdl:message name="getRegionCountryHttpGetIn" /><wsdl:message name="getRegionCountryHttpGetOut"><wsdl:part name="Body" element="tns:ArrayOfString" /></wsdl:message><wsdl:message name="getSupportCityDatasetHttpGetIn"><wsdl:part name="theRegionCode" type="s:string" /></wsdl:message><wsdl:message name="getSupportCityDatasetHttpGetOut"><wsdl:part name="Body" element="tns:DataSet" /></wsdl:message><wsdl:message name="getSupportCityStringHttpGetIn"><wsdl:part name="theRegionCode" type="s:string" /></wsdl:message><wsdl:message name="getSupportCityStringHttpGetOut"><wsdl:part name="Body" element="tns:ArrayOfString" /></wsdl:message><wsdl:message name="getWeatherHttpGetIn"><wsdl:part name="theCityCode" type="s:string" /><wsdl:part name="theUserID" type="s:string" /></wsdl:message><wsdl:message name="getWeatherHttpGetOut"><wsdl:part name="Body" element="tns:ArrayOfString" /></wsdl:message><wsdl:message name="getRegionDatasetHttpPostIn" /><wsdl:message name="getRegionDatasetHttpPostOut"><wsdl:part name="Body" element="tns:DataSet" /></wsdl:message><wsdl:message name="getRegionProvinceHttpPostIn" /><wsdl:message name="getRegionProvinceHttpPostOut"><wsdl:part name="Body" element="tns:ArrayOfString" /></wsdl:message><wsdl:message name="getRegionCountryHttpPostIn" /><wsdl:message name="getRegionCountryHttpPostOut"><wsdl:part name="Body" element="tns:ArrayOfString" /></wsdl:message><wsdl:message name="getSupportCityDatasetHttpPostIn"><wsdl:part name="theRegionCode" type="s:string" /></wsdl:message><wsdl:message name="getSupportCityDatasetHttpPostOut"><wsdl:part name="Body" element="tns:DataSet" /></wsdl:message><wsdl:message name="getSupportCityStringHttpPostIn"><wsdl:part name="theRegionCode" type="s:string" /></wsdl:message><wsdl:message name="getSupportCityStringHttpPostOut"><wsdl:part name="Body" element="tns:ArrayOfString" /></wsdl:message><wsdl:message name="getWeatherHttpPostIn"><wsdl:part name="theCityCode" type="s:string" /><wsdl:part name="theUserID" type="s:string" /></wsdl:message><wsdl:message name="getWeatherHttpPostOut"><wsdl:part name="Body" element="tns:ArrayOfString" /></wsdl:message><wsdl:portType name="WeatherWSSoap"><wsdl:operation name="getRegionDataset"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得中国省份、直辖市、地区;国家名称(国外)和与之对应的ID</h3><p>输入参数:无,返回数据:DataSet。</p><br/></wsdl:documentation><wsdl:input message="tns:getRegionDatasetSoapIn" /><wsdl:output message="tns:getRegionDatasetSoapOut" /></wsdl:operation><wsdl:operation name="getRegionProvince"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得中国省份、直辖市、地区和与之对应的ID</h3><p>输入参数:无,返回数据:一维字符串数组。</p><br/></wsdl:documentation><wsdl:input message="tns:getRegionProvinceSoapIn" /><wsdl:output message="tns:getRegionProvinceSoapOut" /></wsdl:operation><wsdl:operation name="getRegionCountry"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得国外国家名称和与之对应的ID</h3><p>输入参数:无,返回数据:一维字符串数组。</p><br/></wsdl:documentation><wsdl:input message="tns:getRegionCountrySoapIn" /><wsdl:output message="tns:getRegionCountrySoapOut" /></wsdl:operation><wsdl:operation name="getSupportCityDataset"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得支持的城市/地区名称和与之对应的ID</h3><p>输入参数:theRegionCode= 省市、国家ID或名称,返回数据:DataSet。</p><br /></wsdl:documentation><wsdl:input message="tns:getSupportCityDatasetSoapIn" /><wsdl:output message="tns:getSupportCityDatasetSoapOut" /></wsdl:operation><wsdl:operation name="getSupportCityString"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得支持的城市/地区名称和与之对应的ID</h3><p>输入参数:theRegionCode= 省市、国家ID或名称,返回数据:一维字符串数组。</p><br /></wsdl:documentation><wsdl:input message="tns:getSupportCityStringSoapIn" /><wsdl:output message="tns:getSupportCityStringSoapOut" /></wsdl:operation><wsdl:operation name="getWeather"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得天气预报数据</h3><p>输入参数:城市/地区ID或名称,返回数据:一维字符串数组。</p><br/></wsdl:documentation><wsdl:input message="tns:getWeatherSoapIn" /><wsdl:output message="tns:getWeatherSoapOut" /></wsdl:operation></wsdl:portType><wsdl:portType name="WeatherWSHttpGet"><wsdl:operation name="getRegionDataset"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得中国省份、直辖市、地区;国家名称(国外)和与之对应的ID</h3><p>输入参数:无,返回数据:DataSet。</p><br/></wsdl:documentation><wsdl:input message="tns:getRegionDatasetHttpGetIn" /><wsdl:output message="tns:getRegionDatasetHttpGetOut" /></wsdl:operation><wsdl:operation name="getRegionProvince"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得中国省份、直辖市、地区和与之对应的ID</h3><p>输入参数:无,返回数据:一维字符串数组。</p><br/></wsdl:documentation><wsdl:input message="tns:getRegionProvinceHttpGetIn" /><wsdl:output message="tns:getRegionProvinceHttpGetOut" /></wsdl:operation><wsdl:operation name="getRegionCountry"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得国外国家名称和与之对应的ID</h3><p>输入参数:无,返回数据:一维字符串数组。</p><br/></wsdl:documentation><wsdl:input message="tns:getRegionCountryHttpGetIn" /><wsdl:output message="tns:getRegionCountryHttpGetOut" /></wsdl:operation><wsdl:operation name="getSupportCityDataset"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得支持的城市/地区名称和与之对应的ID</h3><p>输入参数:theRegionCode= 省市、国家ID或名称,返回数据:DataSet。</p><br /></wsdl:documentation><wsdl:input message="tns:getSupportCityDatasetHttpGetIn" /><wsdl:output message="tns:getSupportCityDatasetHttpGetOut" /></wsdl:operation><wsdl:operation name="getSupportCityString"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得支持的城市/地区名称和与之对应的ID</h3><p>输入参数:theRegionCode= 省市、国家ID或名称,返回数据:一维字符串数组。</p><br /></wsdl:documentation><wsdl:input message="tns:getSupportCityStringHttpGetIn" /><wsdl:output message="tns:getSupportCityStringHttpGetOut" /></wsdl:operation><wsdl:operation name="getWeather"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得天气预报数据</h3><p>输入参数:城市/地区ID或名称,返回数据:一维字符串数组。</p><br/></wsdl:documentation><wsdl:input message="tns:getWeatherHttpGetIn" /><wsdl:output message="tns:getWeatherHttpGetOut" /></wsdl:operation></wsdl:portType><wsdl:portType name="WeatherWSHttpPost"><wsdl:operation name="getRegionDataset"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得中国省份、直辖市、地区;国家名称(国外)和与之对应的ID</h3><p>输入参数:无,返回数据:DataSet。</p><br/></wsdl:documentation><wsdl:input message="tns:getRegionDatasetHttpPostIn" /><wsdl:output message="tns:getRegionDatasetHttpPostOut" /></wsdl:operation><wsdl:operation name="getRegionProvince"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得中国省份、直辖市、地区和与之对应的ID</h3><p>输入参数:无,返回数据:一维字符串数组。</p><br/></wsdl:documentation><wsdl:input message="tns:getRegionProvinceHttpPostIn" /><wsdl:output message="tns:getRegionProvinceHttpPostOut" /></wsdl:operation><wsdl:operation name="getRegionCountry"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得国外国家名称和与之对应的ID</h3><p>输入参数:无,返回数据:一维字符串数组。</p><br/></wsdl:documentation><wsdl:input message="tns:getRegionCountryHttpPostIn" /><wsdl:output message="tns:getRegionCountryHttpPostOut" /></wsdl:operation><wsdl:operation name="getSupportCityDataset"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得支持的城市/地区名称和与之对应的ID</h3><p>输入参数:theRegionCode= 省市、国家ID或名称,返回数据:DataSet。</p><br /></wsdl:documentation><wsdl:input message="tns:getSupportCityDatasetHttpPostIn" /><wsdl:output message="tns:getSupportCityDatasetHttpPostOut" /></wsdl:operation><wsdl:operation name="getSupportCityString"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得支持的城市/地区名称和与之对应的ID</h3><p>输入参数:theRegionCode= 省市、国家ID或名称,返回数据:一维字符串数组。</p><br /></wsdl:documentation><wsdl:input message="tns:getSupportCityStringHttpPostIn" /><wsdl:output message="tns:getSupportCityStringHttpPostOut" /></wsdl:operation><wsdl:operation name="getWeather"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br/><h3>获得天气预报数据</h3><p>输入参数:城市/地区ID或名称,返回数据:一维字符串数组。</p><br/></wsdl:documentation><wsdl:input message="tns:getWeatherHttpPostIn" /><wsdl:output message="tns:getWeatherHttpPostOut" /></wsdl:operation></wsdl:portType><wsdl:binding name="WeatherWSSoap" type="tns:WeatherWSSoap"><soap:binding transport="http://schemas.xmlsoap.org/soap/http" /><wsdl:operation name="getRegionDataset"><soap:operation soapAction="http://WebXml.com.cn/getRegionDataset"style="document" /><wsdl:input><soap:body use="literal" /></wsdl:input><wsdl:output><soap:body use="literal" /></wsdl:output></wsdl:operation><wsdl:operation name="getRegionProvince"><soap:operation soapAction="http://WebXml.com.cn/getRegionProvince"style="document" /><wsdl:input><soap:body use="literal" /></wsdl:input><wsdl:output><soap:body use="literal" /></wsdl:output></wsdl:operation><wsdl:operation name="getRegionCountry"><soap:operation soapAction="http://WebXml.com.cn/getRegionCountry"style="document" /><wsdl:input><soap:body use="literal" /></wsdl:input><wsdl:output><soap:body use="literal" /></wsdl:output></wsdl:operation><wsdl:operation name="getSupportCityDataset"><soap:operation soapAction="http://WebXml.com.cn/getSupportCityDataset"style="document" /><wsdl:input><soap:body use="literal" /></wsdl:input><wsdl:output><soap:body use="literal" /></wsdl:output></wsdl:operation><wsdl:operation name="getSupportCityString"><soap:operation soapAction="http://WebXml.com.cn/getSupportCityString"style="document" /><wsdl:input><soap:body use="literal" /></wsdl:input><wsdl:output><soap:body use="literal" /></wsdl:output></wsdl:operation><wsdl:operation name="getWeather"><soap:operation soapAction="http://WebXml.com.cn/getWeather"style="document" /><wsdl:input><soap:body use="literal" /></wsdl:input><wsdl:output><soap:body use="literal" /></wsdl:output></wsdl:operation></wsdl:binding><wsdl:binding name="WeatherWSSoap12" type="tns:WeatherWSSoap"><soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /><wsdl:operation name="getRegionDataset"><soap12:operation soapAction="http://WebXml.com.cn/getRegionDataset"style="document" /><wsdl:input><soap12:body use="literal" /></wsdl:input><wsdl:output><soap12:body use="literal" /></wsdl:output></wsdl:operation><wsdl:operation name="getRegionProvince"><soap12:operation soapAction="http://WebXml.com.cn/getRegionProvince"style="document" /><wsdl:input><soap12:body use="literal" /></wsdl:input><wsdl:output><soap12:body use="literal" /></wsdl:output></wsdl:operation><wsdl:operation name="getRegionCountry"><soap12:operation soapAction="http://WebXml.com.cn/getRegionCountry"style="document" /><wsdl:input><soap12:body use="literal" /></wsdl:input><wsdl:output><soap12:body use="literal" /></wsdl:output></wsdl:operation><wsdl:operation name="getSupportCityDataset"><soap12:operation soapAction="http://WebXml.com.cn/getSupportCityDataset"style="document" /><wsdl:input><soap12:body use="literal" /></wsdl:input><wsdl:output><soap12:body use="literal" /></wsdl:output></wsdl:operation><wsdl:operation name="getSupportCityString"><soap12:operation soapAction="http://WebXml.com.cn/getSupportCityString"style="document" /><wsdl:input><soap12:body use="literal" /></wsdl:input><wsdl:output><soap12:body use="literal" /></wsdl:output></wsdl:operation><wsdl:operation name="getWeather"><soap12:operation soapAction="http://WebXml.com.cn/getWeather"style="document" /><wsdl:input><soap12:body use="literal" /></wsdl:input><wsdl:output><soap12:body use="literal" /></wsdl:output></wsdl:operation></wsdl:binding><wsdl:binding name="WeatherWSHttpGet" type="tns:WeatherWSHttpGet"><http:binding verb="GET" /><wsdl:operation name="getRegionDataset"><http:operation location="/getRegionDataset" /><wsdl:input><http:urlEncoded /></wsdl:input><wsdl:output><mime:mimeXml part="Body" /></wsdl:output></wsdl:operation><wsdl:operation name="getRegionProvince"><http:operation location="/getRegionProvince" /><wsdl:input><http:urlEncoded /></wsdl:input><wsdl:output><mime:mimeXml part="Body" /></wsdl:output></wsdl:operation><wsdl:operation name="getRegionCountry"><http:operation location="/getRegionCountry" /><wsdl:input><http:urlEncoded /></wsdl:input><wsdl:output><mime:mimeXml part="Body" /></wsdl:output></wsdl:operation><wsdl:operation name="getSupportCityDataset"><http:operation location="/getSupportCityDataset" /><wsdl:input><http:urlEncoded /></wsdl:input><wsdl:output><mime:mimeXml part="Body" /></wsdl:output></wsdl:operation><wsdl:operation name="getSupportCityString"><http:operation location="/getSupportCityString" /><wsdl:input><http:urlEncoded /></wsdl:input><wsdl:output><mime:mimeXml part="Body" /></wsdl:output></wsdl:operation><wsdl:operation name="getWeather"><http:operation location="/getWeather" /><wsdl:input><http:urlEncoded /></wsdl:input><wsdl:output><mime:mimeXml part="Body" /></wsdl:output></wsdl:operation></wsdl:binding><wsdl:binding name="WeatherWSHttpPost" type="tns:WeatherWSHttpPost"><http:binding verb="POST" /><wsdl:operation name="getRegionDataset"><http:operation location="/getRegionDataset" /><wsdl:input><mime:content type="application/x-www-form-urlencoded" /></wsdl:input><wsdl:output><mime:mimeXml part="Body" /></wsdl:output></wsdl:operation><wsdl:operation name="getRegionProvince"><http:operation location="/getRegionProvince" /><wsdl:input><mime:content type="application/x-www-form-urlencoded" /></wsdl:input><wsdl:output><mime:mimeXml part="Body" /></wsdl:output></wsdl:operation><wsdl:operation name="getRegionCountry"><http:operation location="/getRegionCountry" /><wsdl:input><mime:content type="application/x-www-form-urlencoded" /></wsdl:input><wsdl:output><mime:mimeXml part="Body" /></wsdl:output></wsdl:operation><wsdl:operation name="getSupportCityDataset"><http:operation location="/getSupportCityDataset" /><wsdl:input><mime:content type="application/x-www-form-urlencoded" /></wsdl:input><wsdl:output><mime:mimeXml part="Body" /></wsdl:output></wsdl:operation><wsdl:operation name="getSupportCityString"><http:operation location="/getSupportCityString" /><wsdl:input><mime:content type="application/x-www-form-urlencoded" /></wsdl:input><wsdl:output><mime:mimeXml part="Body" /></wsdl:output></wsdl:operation><wsdl:operation name="getWeather"><http:operation location="/getWeather" /><wsdl:input><mime:content type="application/x-www-form-urlencoded" /></wsdl:input><wsdl:output><mime:mimeXml part="Body" /></wsdl:output></wsdl:operation></wsdl:binding><wsdl:service name="WeatherWS"><wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><ahref="http://www.webxml.com.cn/"target="_blank">WebXml.com.cn</a><strong>2400多个城市天气预报Web服务</strong>,包含2300个以上中国城市和100个以上国外城市天气预报数据。数据每2.5小时左右自动更新一次,准确可靠。<br/>使用本站 WEB 服务请注明或链接本站:<a href="http://www.webxml.com.cn/"target="_blank">http://www.webxml.com.cn/</a> 感谢大家的支持!<br/><br /><img alt="PDF" title="PDF file"src="http://www.webxml.com.cn/images/icon/pdf.gif"style="vertical-align: middle;" /> <ahref="http://www.webxml.com.cn/files/WeatherWsHelp.pdf"target="_blank">接口帮助文档</a> &nbsp;&nbsp;&nbsp;<img alt="ZIP" title="ZIP file"src="http://www.webxml.com.cn/images/icon/zip.gif"style="vertical-align: middle;" /> <ahref="http://www.webxml.com.cn/files/about_city.zip">部分城市介绍和气候背景</a>&nbsp;&nbsp;&nbsp; <img alt="ZIP" title="ZIP file"src="http://www.webxml.com.cn/images/icon/zip.gif"style="vertical-align: middle;" /> <ahref="http://www.webxml.com.cn/files/city_photo.zip">部分城市图片</a>&nbsp;&nbsp;&nbsp; <img alt="HTML" title="HTML file"src="http://www.webxml.com.cn/images/icon/html.gif"style="vertical-align: middle;" /> <ahref="http://www.webxml.com.cn/zh_cn/weather_icon.aspx"target="_blank">天气现象和图例</a><br />&nbsp;</wsdl:documentation><wsdl:port name="WeatherWSSoap" binding="tns:WeatherWSSoap"><soap:address location="http://ws.webxml.com.cn/WebServices/WeatherWS.asmx" /></wsdl:port><wsdl:port name="WeatherWSSoap12" binding="tns:WeatherWSSoap12"><soap12:address location="http://ws.webxml.com.cn/WebServices/WeatherWS.asmx" /></wsdl:port><wsdl:port name="WeatherWSHttpGet" binding="tns:WeatherWSHttpGet"><http:address location="http://ws.webxml.com.cn/WebServices/WeatherWS.asmx" /></wsdl:port><wsdl:port name="WeatherWSHttpPost" binding="tns:WeatherWSHttpPost"><http:address location="http://ws.webxml.com.cn/WebServices/WeatherWS.asmx" /></wsdl:port></wsdl:service>
</wsdl:definitions>
然后在dos窗口中,使用文本解析即可。
虽然有警告,但是生成文件了 。
然后我们尝试调用这个天气预报的接口:
所以根文件是WeatherWS
客户端调用代码:
package cn.com.webxml.test;import java.util.List;import cn.com.webxml.ArrayOfString;
import cn.com.webxml.WeatherWS;
import cn.com.webxml.WeatherWSSoap;public class WSReportTest {public static void main(String[] args) {WeatherWS weatherWS=new WeatherWS();WeatherWSSoap weatherWSSoap = weatherWS.getWeatherWSSoap();ArrayOfString weather = weatherWSSoap.getWeather("北京", null);List<String> list = weather.getString();for(String str:list){System.out.println(str);}}}
运行结果为:
同理,可以尝试调用国内手机号码归属地查询WEB服务。
2.编写手机号码归属地的webservice
url地址:http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?op=getMobileCodeInfo
wsdl的链接:http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
调用代码:
package cn.com.webxml.test;import cn.com.webxml.MobileCodeWS;
import cn.com.webxml.MobileCodeWSSoap;public class WSModelTest {public static void main(String[] args) {MobileCodeWS mobileCodeWS=new MobileCodeWS();MobileCodeWSSoap mobileCodeWSSoap = mobileCodeWS.getMobileCodeWSSoap();String mobileCodeInfo = mobileCodeWSSoap.getMobileCodeInfo("15713329014", null);System.out.println(mobileCodeInfo);}}
运行结果:
其他接口的调用也是类似,不再赘述。
webservice 教程学习系列(七)——编写天气预报和手机号码归属地的webservice相关推荐
- webservice 教程学习系列(一)——schema约束
最近同事在做一个webservice 接口的调用,我比较感兴趣,所以就找时间学习了一下.在此写下我学习的全过程,算是记个笔记吧!如有不足或者错误之处,欢迎指摘. 因为大部分的webservice是通过 ...
- Android音视频学习系列(七) — 从0~1开发一款Android端播放器(支持多协议网络拉流本地文件)
系列文章 Android音视频学习系列(一) - JNI从入门到精通 Android音视频学习系列(二) - 交叉编译动态库.静态库的入门 Android音视频学习系列(三) - Shell脚本入门 ...
- opencv-python教程学习系列2-读取/显示/保存图像
前言 opencv-python教程学习系列记录学习python-opencv过程的点滴,本文主要介绍图像的读取.显示以及保存,坚持学习,共同进步. 系列教程参照OpenCV-Python中文教程: ...
- opencv-python教程学习系列13-图像平滑
前言 opencv-python教程学习系列记录学习python-opencv过程的点滴,本文主要介绍图像平滑,坚持学习,共同进步. 系列教程参照OpenCV-Python中文教程: 系统环境 系统: ...
- python 几何教学_opencv-python教程学习系列11-几何变换
前言 opencv-python教程学习系列记录学习python-opencv过程的点滴,本文主要介绍几何变换,坚持学习,共同进步. 系统环境 系统:win7_x64; python版本:python ...
- unixlinux大学教程学习 第七章
unix&linux大学教程学习 第七章 学习了第七章. 主要讲解键盘信号 每一个键盘对应一个信号.主要的有: ^代表 Ctrl <Backspance> erase ,删除一个字 ...
- scrapy爬虫学习系列七:scrapy常见问题解决方案
scrapy爬虫学习系列七:scrapy常见问题解决方案 参考文章: (1)scrapy爬虫学习系列七:scrapy常见问题解决方案 (2)https://www.cnblogs.com/zhaoji ...
- python鼠标点击事件event_opencv-python教程学习系列5-处理鼠标事件
前言 opencv-python教程学习系列记录学习python-opencv过程的点滴,本文主要介绍opencv-python处理鼠标事件,坚持学习,共同进步. 系统环境 系统:win_x64; p ...
- Vue.js学习系列七——Vue服务器渲染Nuxt学习
我又回来啦~这次我们来学习Vue的服务器渲染SSR. 关于SSR的文章网上很多,一开始看得我云里雾里.然后去Vue.js 服务器渲染指南和nuxt官网看了看,发现文章大多都是搬运官网的内容,真正讲的清 ...
最新文章
- convertViewsetTag方法的一点理解
- 智能制造大潮下,机器视觉产业迎来春天?
- [afterCode] docker 速成班 1: image
- 牛顿-拉夫逊法进行潮流计算matlab源程序
- 十八、数据容器、数据访问宽度、端口(计算机对数据处理方式:读取、写入、运算;数据可存放三个地方:CPU内部、内存、端口)
- 数据结构-03-队列
- firefox火狐集成idm
- 实时互动白板_使用froala文本编辑器构建实时协作白板第1部分
- 计算机WIN7安装,教您win7旗舰版安装教程
- 微信小程序开发——调用免费天气api接口(高德、天气API)
- groovy_流利的Groovy
- pat甲级考试报名费_2019吉林省公务员考试笔面心得
- 高数-不定积分-分部积分法
- greenplum数据导入到mysql,greenplum数据库常用操作
- 基于 HTML+CSS+JS 的纸牌记忆游戏
- 【正点原子MP157连载】第二十章 字符设备驱动开发-摘自【正点原子】STM32MP1嵌入式Linux驱动开发指南V1.7
- PCM音频数据音量大小调节
- 智慧能源物联网云平台方案
- 启用计算机图标,windows如何启用管理员及桌面图标设置?
- Div元素 html