webservice获取天气信息

2023-06-07,,

效果


1、eclipse中新建一个Java项目

2、通过命名获取天气的客户端信息

首先,打开天气网站http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl

然后,在Java项目的src目录下,新建一个文档weather.wsdl,文件名可以不一样

打开文件,把天气网站的所有文字复制粘贴到这个文件中

 <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/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://WebXml.com.cn/">
<wsdl:documentation
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<a href="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;" />
<a href="http://www.webxml.com.cn/files/WeatherWsHelp.pdf"
target="_blank">接口帮助文档</a> &amp;nbsp;&amp;nbsp;&amp;nbsp;
<img alt="ZIP" title="ZIP file"
src="http://www.webxml.com.cn/images/icon/zip.gif"
style="vertical-align: middle;" />
<a href="http://www.webxml.com.cn/files/about_city.zip">部分城市介绍和气候背景</a> &amp;nbsp;&amp;nbsp;&amp;nbsp;
<img alt="ZIP" title="ZIP file"
src="http://www.webxml.com.cn/images/icon/zip.gif"
style="vertical-align: middle;" />
<a href="http://www.webxml.com.cn/files/city_photo.zip">部分城市图片</a> &amp;nbsp;&amp;nbsp;&amp;nbsp;
<img alt="HTML" title="HTML file"
src="http://www.webxml.com.cn/images/icon/html.gif"
style="vertical-align: middle;" />
<a href="http://www.webxml.com.cn/zh_cn/weather_icon.aspx"
target="_blank">天气现象和图例</a>
<br />&amp;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 />
</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 />
</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 />
</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/">
<a href="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;" />
<a href="http://www.webxml.com.cn/files/WeatherWsHelp.pdf"
target="_blank">接口帮助文档</a> &amp;nbsp;&amp;nbsp;&amp;nbsp;
<img alt="ZIP" title="ZIP file"
src="http://www.webxml.com.cn/images/icon/zip.gif"
style="vertical-align: middle;" />
<a href="http://www.webxml.com.cn/files/about_city.zip">部分城市介绍和气候背景</a> &amp;nbsp;&amp;nbsp;&amp;nbsp;
<img alt="ZIP" title="ZIP file"
src="http://www.webxml.com.cn/images/icon/zip.gif"
style="vertical-align: middle;" />
<a href="http://www.webxml.com.cn/files/city_photo.zip">部分城市图片</a> &amp;nbsp;&amp;nbsp;&amp;nbsp;
<img alt="HTML" title="HTML file"
src="http://www.webxml.com.cn/images/icon/html.gif"
style="vertical-align: middle;" />
<a href="http://www.webxml.com.cn/zh_cn/weather_icon.aspx"
target="_blank">天气现象和图例</a>
<br />&amp;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>

weather.wsdl

接着,到这个文件中,Ctrl+F,把<s:element ref="s:schema" />全部删除

还要把&nbsp;替换为&amp;nbsp;

最后,win+R打开运行,输入cmd,到新建项目的src目录下,输入命令wsimport -keep weather.wsdl(后面这个是文件名)

注:如果发生以下提示(wsimport 不是内部或外部命令,也不是可运行的程序或批处理文件)

解决方法,参考文章:https://blog.csdn.net/jiudihanbing/article/details/52382508

3、创建开启客户端

 package cn.com.webxml;

 import java.net.MalformedURLException;
import java.net.URL;
import java.util.List; import javax.xml.namespace.QName;
import javax.xml.ws.Service; /**
* @desc 客户端
* @author xiaostudy
*
*/
public class MyClient { public static void main(String[] args) {
//=============================================================================
//第一种方式获取视图
WeatherWS weatherWS = new WeatherWS();
//获取服务实现类
WeatherWSSoap weatherWSSoap = weatherWS.getPort(WeatherWSSoap.class);
//============================================================================= //=============================================================================
//第二种方式获取视图
/*URL url = null;
try {
url = new URL("http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl");
} catch (MalformedURLException e) {
e.printStackTrace();
} QName qName = new QName("http://WebXml.com.cn/", "WeatherWS"); Service service = Service.create(url, qName);
WeatherWSSoap weatherWSSoap = service.getPort(WeatherWSSoap.class);*/
//============================================================================= //调用服务器接口,发送数据并返回数据
ArrayOfString arrayOfString = weatherWSSoap.getWeather("广州", "");
//控制台打印数据
List<String> list = arrayOfString.getString();
for(String str : list) {
System.out.println(str);
}
} }

MyClient.java

 package cn.com.webxml;

 import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL; /**
* @desc 客户端
* @author xiaostudy
*
*/
public class MyClient3 { public static void main(String[] args) {
try {
//第一步:创建服务地址,不是WSDL地址
URL url = new URL("http://ws.webxml.com.cn/WebServices/WeatherWS.asmx");
//第二步:打开一个通向服务地址的连接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//第三步:设置参数
//3.1发送方式设置:POST必须大写
connection.setRequestMethod("POST");
//3.2设置数据格式:content-type
connection.setRequestProperty("content-type", "text/xml;charset=utf-8");
//3.3设置输入输出,因为默认新创建的connection没有读写权限
connection.setDoInput(true);
connection.setDoOutput(true);
//第四步:组织SOAP数据,发送请求
String xml = getXml("广州");
OutputStream os = connection.getOutputStream();
os.write(xml.getBytes());
//第五步:接收服务端响应,打印
int responseCode = connection.getResponseCode();
//5.1判断响应吗是否为200(200表示一切正常)
if(responseCode == 200) {
//读取数据
InputStream is = connection.getInputStream();
//转化为字符流
InputStreamReader isr = new InputStreamReader(is);
//包装
BufferedReader br = new BufferedReader(isr);
StringBuffer sb = new StringBuffer();
String temp = null;
while(null != (temp = br.readLine())) {
sb.append(temp);
}
System.out.println(sb.toString()); //关闭资源
if(is != null) {
is.close();
is = null;
}
if(isr != null) {
isr.close();
isr = null;
}
if(br != null) {
br.close();
br = null;
}
if(os != null) {
os.close();
os = null;
}
}
} catch (IOException e) {
e.printStackTrace();
} } /**
* @desc 封装数据的方法
* @param str 参数,城市名
* @return String 返回类型,返回数据
*/
private static String getXml(String str) {
//前面两行和后面两行是固定格式,
//<getWeather>是调用的方法
//<theCityCode>和<theUserID>是调用方法里面的参数
String soapXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+"<soap:Body>"
+"<getWeather xmlns=\"http://WebXml.com.cn/\">"
+"<theCityCode>"+str+"</theCityCode>"
+"<theUserID></theUserID>"
+"</getWeather>"
+"</soap:Body>"
+"</soap:Envelope>";
return soapXML;
} }

MyClient3.java

4、运行客户端看结果,右键Run As→Java Application


webservice获取天气信息的相关教程结束。

《webservice获取天气信息.doc》

下载本文的Word格式文档,以方便收藏与打印。