效果


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获取天气信息的更多相关文章

  1. Kettle通过Webservice获取天气信息

      Kettle通过Webservice获取天气信息 需求: 通过kettle工具,通过webservice获取天气信息,写成xml格式文件. 思路: Kettle可通过两种选择获取webservic ...

  2. C#调用WebService获取天气信息

    概述 本文使用C#开发Winform应用程序,通过调用<WebXml/>(URL:http://www.webxml.com.cn)的WebService服务WeatherWS来获取天气预 ...

  3. Java通过webservice接口获取天气信息

    通过SOAP请求的方式获取天气信息并解析返回的XML文件. 参考: http://www.webxml.com.cn/WebServices/WeatherWS.asmx import java.io ...

  4. 内网公告牌获取天气信息解决方案(C# WebForm)

    需求:内网公告牌能够正确显示未来三天的天气信息 本文关键字:C#/WebForm/Web定时任务/Ajax跨域 规划: 1.天定时读取百度接口获取天气信息并存储至Txt文档: 2.示牌开启时请求Web ...

  5. ajax无刷新获取天气信息

    浏览器由于安全方面的问题,禁止ajax跨域请求其他网站的数据,但是可以再本地的服务器上获取其他服务器的信息,在通过ajax请求本地服务来实现: <?php header("conten ...

  6. 半吊子学习Swift--天气预报程序-获取天气信息

    昨天申请的彩云天气Api开发者今天上午已审核通过  饭后运动过后就马不停蹄的来测试接口,接口是采用经纬度的方式来获取天气信息,接口地址如下 https://api.caiyunapp.com/v2/ ...

  7. java获取天气信息

    通过天气信息接口获取天气信息,首先要给项目导入程序所需要的包,具体需要如下几个包: json-lib-2.4.jar ezmorph-1.0.6.jar commons-beanutils-1.8.3 ...

  8. Android实现自动定位城市并获取天气信息

    定位实现代码: <span style="font-size:14px;">import java.io.IOException; import java.util.L ...

  9. java解析xml实例——获取天气信息

    获取xml并解析其中的数据: package getweather.xml; import java.io.IOException; import java.util.HashMap; import ...

随机推荐

  1. flask建立数据模型数据类型

    https://blog.csdn.net/happyanger6/article/details/53947162 https://blog.csdn.net/happyanger6/article ...

  2. 前端开发 - jsBom

    一.jsBom简介 jsBom = javascript browser object modelBOM指的是浏览器对象模型 Browser Object Model,它的核心就是浏览器. 二.Bom ...

  3. 剑指Offer——字符串的排列

    题目描述: 输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba. 输入描述: ...

  4. CheckStyle——检查编码格式等是否符合规范

    CheckStyle 一.checkstyle简介 checkstyle是idea中的一个插件,可以很方便的帮我们检查java代码中的格式错误,它能够自动化代码规范检查过程,从而使得开发人员从这项重要 ...

  5. Kafka笔记整理(一)

    Kafka简介 消息队列(Message Queue) 消息 Message 网络中的两台计算机或者两个通讯设备之间传递的数据.例如说:文本.音乐.视频等内容. 队列 Queue 一种特殊的线性表(数 ...

  6. mutex_lock

    多核处理器下,会存在多个进程处于内核态的情况,而在内核态下,进程是可以访问所有内核数据的,因此要对共享数据进行保护,即互斥处理. mutex_lock(struct mutex *lock)和mute ...

  7. boost circular buffer环形缓冲类

    Boost.Circular_buffer维护了一块连续内存块作为缓存区,当缓存区内的数据存满时,继续存入数据就覆盖掉旧的数据. 它是一个与STL兼容的容器,类似于 std::list或std::de ...

  8. cmd 导出导入数据库

    cmd导出 1.

  9. 10、property

    成人的BMI数值:过轻:低于18.5正常:18.5-23.9过重:24-27肥胖:28-32非常肥胖, 高于32 体质指数(BMI)=体重(kg)÷身高^2(m) EX:70kg÷(1.75×1.75 ...

  10. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League

    地址:http://codeforces.com/contest/782/problem/D 题目: D. Innokenty and a Football League time limit per ...