webservice获取天气信息

效果


1、eclipse中新建一个Java项目

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

首先,打开天气网站http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl
然后,在Java项目的src目录下,新建一个文档weather.wsdl,文件名可以不一样

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

  1 <wsdl:definitions
  2     xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
  3     xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
  4     xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
  5     xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
  6     xmlns:tns="http://WebXml.com.cn/"
  7     xmlns:s="http://www.w3.org/2001/XMLSchema"
  8     xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
  9     xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
 10     xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
 11     targetNamespace="http://WebXml.com.cn/">
 12     <wsdl:documentation
 13         xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
 14         <a href="http://www.webxml.com.cn/" target="_blank">WebXml.com.cn</a>
 15         <strong>2400多个城市天气预报Web服务</strong>
 16         ,包含2300个以上中国城市和100个以上国外城市天气预报数据。数据每2.5小时左右自动更新一次,准确可靠。
 17         <br />
 18         使用本站 WEB 服务请注明或链接本站:
 19         <a href="http://www.webxml.com.cn/" target="_blank">http://www.webxml.com.cn/</a>
 20         感谢大家的支持!
 21         <br />
 22         <br />
 23         <img alt="PDF" title="PDF file"
 24             src="http://www.webxml.com.cn/images/icon/pdf.gif"
 25             style="vertical-align: middle;" />
 26         <a href="http://www.webxml.com.cn/files/WeatherWsHelp.pdf"
 27             target="_blank">接口帮助文档</a> &amp;nbsp;&amp;nbsp;&amp;nbsp;
 28         <img alt="ZIP" title="ZIP file"
 29             src="http://www.webxml.com.cn/images/icon/zip.gif"
 30             style="vertical-align: middle;" />
 31         <a href="http://www.webxml.com.cn/files/about_city.zip">部分城市介绍和气候背景</a> &amp;nbsp;&amp;nbsp;&amp;nbsp;
 32         <img alt="ZIP" title="ZIP file"
 33             src="http://www.webxml.com.cn/images/icon/zip.gif"
 34             style="vertical-align: middle;" />
 35         <a href="http://www.webxml.com.cn/files/city_photo.zip">部分城市图片</a> &amp;nbsp;&amp;nbsp;&amp;nbsp;
 36         <img alt="HTML" title="HTML file"
 37             src="http://www.webxml.com.cn/images/icon/html.gif"
 38             style="vertical-align: middle;" />
 39         <a href="http://www.webxml.com.cn/zh_cn/weather_icon.aspx"
 40             target="_blank">天气现象和图例</a>
 41         <br />&amp;nbsp;
 42     </wsdl:documentation>
 43     <wsdl:types>
 44         <s:schema elementFormDefault="qualified"
 45             targetNamespace="http://WebXml.com.cn/">
 46             <s:element name="getRegionDataset">
 47                 <s:complexType />
 48             </s:element>
 49             <s:element name="getRegionDatasetResponse">
 50                 <s:complexType>
 51                     <s:sequence>
 52                         <s:element minOccurs="0" maxOccurs="1"
 53                             name="getRegionDatasetResult">
 54                             <s:complexType>
 55                                 <s:sequence>
 56                                     <s:any />
 57                                 </s:sequence>
 58                             </s:complexType>
 59                         </s:element>
 60                     </s:sequence>
 61                 </s:complexType>
 62             </s:element>
 63             <s:element name="getRegionProvince">
 64                 <s:complexType />
 65             </s:element>
 66             <s:element name="getRegionProvinceResponse">
 67                 <s:complexType>
 68                     <s:sequence>
 69                         <s:element minOccurs="0" maxOccurs="1"
 70                             name="getRegionProvinceResult" type="tns:ArrayOfString" />
 71                     </s:sequence>
 72                 </s:complexType>
 73             </s:element>
 74             <s:complexType name="ArrayOfString">
 75                 <s:sequence>
 76                     <s:element minOccurs="0" maxOccurs="unbounded"
 77                         name="string" nillable="true" type="s:string" />
 78                 </s:sequence>
 79             </s:complexType>
 80             <s:element name="getRegionCountry">
 81                 <s:complexType />
 82             </s:element>
 83             <s:element name="getRegionCountryResponse">
 84                 <s:complexType>
 85                     <s:sequence>
 86                         <s:element minOccurs="0" maxOccurs="1"
 87                             name="getRegionCountryResult" type="tns:ArrayOfString" />
 88                     </s:sequence>
 89                 </s:complexType>
 90             </s:element>
 91             <s:element name="getSupportCityDataset">
 92                 <s:complexType>
 93                     <s:sequence>
 94                         <s:element minOccurs="0" maxOccurs="1"
 95                             name="theRegionCode" type="s:string" />
 96                     </s:sequence>
 97                 </s:complexType>
 98             </s:element>
 99             <s:element name="getSupportCityDatasetResponse">
100                 <s:complexType>
101                     <s:sequence>
102                         <s:element minOccurs="0" maxOccurs="1"
103                             name="getSupportCityDatasetResult">
104                             <s:complexType>
105                                 <s:sequence>
106                                     <s:any />
107                                 </s:sequence>
108                             </s:complexType>
109                         </s:element>
110                     </s:sequence>
111                 </s:complexType>
112             </s:element>
113             <s:element name="getSupportCityString">
114                 <s:complexType>
115                     <s:sequence>
116                         <s:element minOccurs="0" maxOccurs="1"
117                             name="theRegionCode" type="s:string" />
118                     </s:sequence>
119                 </s:complexType>
120             </s:element>
121             <s:element name="getSupportCityStringResponse">
122                 <s:complexType>
123                     <s:sequence>
124                         <s:element minOccurs="0" maxOccurs="1"
125                             name="getSupportCityStringResult" type="tns:ArrayOfString" />
126                     </s:sequence>
127                 </s:complexType>
128             </s:element>
129             <s:element name="getWeather">
130                 <s:complexType>
131                     <s:sequence>
132                         <s:element minOccurs="0" maxOccurs="1"
133                             name="theCityCode" type="s:string" />
134                         <s:element minOccurs="0" maxOccurs="1" name="theUserID"
135                             type="s:string" />
136                     </s:sequence>
137                 </s:complexType>
138             </s:element>
139             <s:element name="getWeatherResponse">
140                 <s:complexType>
141                     <s:sequence>
142                         <s:element minOccurs="0" maxOccurs="1"
143                             name="getWeatherResult" type="tns:ArrayOfString" />
144                     </s:sequence>
145                 </s:complexType>
146             </s:element>
147             <s:element name="DataSet" nillable="true">
148                 <s:complexType>
149                     <s:sequence>
150                         <s:any />
151                     </s:sequence>
152                 </s:complexType>
153             </s:element>
154             <s:element name="ArrayOfString" nillable="true"
155                 type="tns:ArrayOfString" />
156         </s:schema>
157     </wsdl:types>
158     <wsdl:message name="getRegionDatasetSoapIn">
159         <wsdl:part name="parameters" element="tns:getRegionDataset" />
160     </wsdl:message>
161     <wsdl:message name="getRegionDatasetSoapOut">
162         <wsdl:part name="parameters"
163             element="tns:getRegionDatasetResponse" />
164     </wsdl:message>
165     <wsdl:message name="getRegionProvinceSoapIn">
166         <wsdl:part name="parameters" element="tns:getRegionProvince" />
167     </wsdl:message>
168     <wsdl:message name="getRegionProvinceSoapOut">
169         <wsdl:part name="parameters"
170             element="tns:getRegionProvinceResponse" />
171     </wsdl:message>
172     <wsdl:message name="getRegionCountrySoapIn">
173         <wsdl:part name="parameters" element="tns:getRegionCountry" />
174     </wsdl:message>
175     <wsdl:message name="getRegionCountrySoapOut">
176         <wsdl:part name="parameters"
177             element="tns:getRegionCountryResponse" />
178     </wsdl:message>
179     <wsdl:message name="getSupportCityDatasetSoapIn">
180         <wsdl:part name="parameters"
181             element="tns:getSupportCityDataset" />
182     </wsdl:message>
183     <wsdl:message name="getSupportCityDatasetSoapOut">
184         <wsdl:part name="parameters"
185             element="tns:getSupportCityDatasetResponse" />
186     </wsdl:message>
187     <wsdl:message name="getSupportCityStringSoapIn">
188         <wsdl:part name="parameters"
189             element="tns:getSupportCityString" />
190     </wsdl:message>
191     <wsdl:message name="getSupportCityStringSoapOut">
192         <wsdl:part name="parameters"
193             element="tns:getSupportCityStringResponse" />
194     </wsdl:message>
195     <wsdl:message name="getWeatherSoapIn">
196         <wsdl:part name="parameters" element="tns:getWeather" />
197     </wsdl:message>
198     <wsdl:message name="getWeatherSoapOut">
199         <wsdl:part name="parameters"
200             element="tns:getWeatherResponse" />
201     </wsdl:message>
202     <wsdl:message name="getRegionDatasetHttpGetIn" />
203     <wsdl:message name="getRegionDatasetHttpGetOut">
204         <wsdl:part name="Body" element="tns:DataSet" />
205     </wsdl:message>
206     <wsdl:message name="getRegionProvinceHttpGetIn" />
207     <wsdl:message name="getRegionProvinceHttpGetOut">
208         <wsdl:part name="Body" element="tns:ArrayOfString" />
209     </wsdl:message>
210     <wsdl:message name="getRegionCountryHttpGetIn" />
211     <wsdl:message name="getRegionCountryHttpGetOut">
212         <wsdl:part name="Body" element="tns:ArrayOfString" />
213     </wsdl:message>
214     <wsdl:message name="getSupportCityDatasetHttpGetIn">
215         <wsdl:part name="theRegionCode" type="s:string" />
216     </wsdl:message>
217     <wsdl:message name="getSupportCityDatasetHttpGetOut">
218         <wsdl:part name="Body" element="tns:DataSet" />
219     </wsdl:message>
220     <wsdl:message name="getSupportCityStringHttpGetIn">
221         <wsdl:part name="theRegionCode" type="s:string" />
222     </wsdl:message>
223     <wsdl:message name="getSupportCityStringHttpGetOut">
224         <wsdl:part name="Body" element="tns:ArrayOfString" />
225     </wsdl:message>
226     <wsdl:message name="getWeatherHttpGetIn">
227         <wsdl:part name="theCityCode" type="s:string" />
228         <wsdl:part name="theUserID" type="s:string" />
229     </wsdl:message>
230     <wsdl:message name="getWeatherHttpGetOut">
231         <wsdl:part name="Body" element="tns:ArrayOfString" />
232     </wsdl:message>
233     <wsdl:message name="getRegionDatasetHttpPostIn" />
234     <wsdl:message name="getRegionDatasetHttpPostOut">
235         <wsdl:part name="Body" element="tns:DataSet" />
236     </wsdl:message>
237     <wsdl:message name="getRegionProvinceHttpPostIn" />
238     <wsdl:message name="getRegionProvinceHttpPostOut">
239         <wsdl:part name="Body" element="tns:ArrayOfString" />
240     </wsdl:message>
241     <wsdl:message name="getRegionCountryHttpPostIn" />
242     <wsdl:message name="getRegionCountryHttpPostOut">
243         <wsdl:part name="Body" element="tns:ArrayOfString" />
244     </wsdl:message>
245     <wsdl:message name="getSupportCityDatasetHttpPostIn">
246         <wsdl:part name="theRegionCode" type="s:string" />
247     </wsdl:message>
248     <wsdl:message name="getSupportCityDatasetHttpPostOut">
249         <wsdl:part name="Body" element="tns:DataSet" />
250     </wsdl:message>
251     <wsdl:message name="getSupportCityStringHttpPostIn">
252         <wsdl:part name="theRegionCode" type="s:string" />
253     </wsdl:message>
254     <wsdl:message name="getSupportCityStringHttpPostOut">
255         <wsdl:part name="Body" element="tns:ArrayOfString" />
256     </wsdl:message>
257     <wsdl:message name="getWeatherHttpPostIn">
258         <wsdl:part name="theCityCode" type="s:string" />
259         <wsdl:part name="theUserID" type="s:string" />
260     </wsdl:message>
261     <wsdl:message name="getWeatherHttpPostOut">
262         <wsdl:part name="Body" element="tns:ArrayOfString" />
263     </wsdl:message>
264     <wsdl:portType name="WeatherWSSoap">
265         <wsdl:operation name="getRegionDataset">
266             <wsdl:documentation
267                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
268                 <br />
269                 <h3>获得中国省份、直辖市、地区;国家名称(国外)和与之对应的ID</h3>
270                 <p>输入参数:无,返回数据:DataSet。</p>
271                 <br />
272             </wsdl:documentation>
273             <wsdl:input message="tns:getRegionDatasetSoapIn" />
274             <wsdl:output message="tns:getRegionDatasetSoapOut" />
275         </wsdl:operation>
276         <wsdl:operation name="getRegionProvince">
277             <wsdl:documentation
278                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
279                 <br />
280                 <h3>获得中国省份、直辖市、地区和与之对应的ID</h3>
281                 <p>输入参数:无,返回数据:一维字符串数组。</p>
282                 <br />
283             </wsdl:documentation>
284             <wsdl:input message="tns:getRegionProvinceSoapIn" />
285             <wsdl:output message="tns:getRegionProvinceSoapOut" />
286         </wsdl:operation>
287         <wsdl:operation name="getRegionCountry">
288             <wsdl:documentation
289                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
290                 <br />
291                 <h3>获得国外国家名称和与之对应的ID</h3>
292                 <p>输入参数:无,返回数据:一维字符串数组。</p>
293                 <br />
294             </wsdl:documentation>
295             <wsdl:input message="tns:getRegionCountrySoapIn" />
296             <wsdl:output message="tns:getRegionCountrySoapOut" />
297         </wsdl:operation>
298         <wsdl:operation name="getSupportCityDataset">
299             <wsdl:documentation
300                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
301                 <br />
302                 <h3>获得支持的城市/地区名称和与之对应的ID</h3>
303                 <p>输入参数:theRegionCode = 省市、国家ID或名称,返回数据:DataSet。</p>
304                 <br />
305             </wsdl:documentation>
306             <wsdl:input message="tns:getSupportCityDatasetSoapIn" />
307             <wsdl:output message="tns:getSupportCityDatasetSoapOut" />
308         </wsdl:operation>
309         <wsdl:operation name="getSupportCityString">
310             <wsdl:documentation
311                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
312                 <br />
313                 <h3>获得支持的城市/地区名称和与之对应的ID</h3>
314                 <p>输入参数:theRegionCode = 省市、国家ID或名称,返回数据:一维字符串数组。</p>
315                 <br />
316             </wsdl:documentation>
317             <wsdl:input message="tns:getSupportCityStringSoapIn" />
318             <wsdl:output message="tns:getSupportCityStringSoapOut" />
319         </wsdl:operation>
320         <wsdl:operation name="getWeather">
321             <wsdl:documentation
322                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
323                 <br />
324                 <h3>获得天气预报数据</h3>
325                 <p>输入参数:城市/地区ID或名称,返回数据:一维字符串数组。</p>
326                 <br />
327             </wsdl:documentation>
328             <wsdl:input message="tns:getWeatherSoapIn" />
329             <wsdl:output message="tns:getWeatherSoapOut" />
330         </wsdl:operation>
331     </wsdl:portType>
332     <wsdl:portType name="WeatherWSHttpGet">
333         <wsdl:operation name="getRegionDataset">
334             <wsdl:documentation
335                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
336                 <br />
337                 <h3>获得中国省份、直辖市、地区;国家名称(国外)和与之对应的ID</h3>
338                 <p>输入参数:无,返回数据:DataSet。</p>
339                 <br />
340             </wsdl:documentation>
341             <wsdl:input message="tns:getRegionDatasetHttpGetIn" />
342             <wsdl:output message="tns:getRegionDatasetHttpGetOut" />
343         </wsdl:operation>
344         <wsdl:operation name="getRegionProvince">
345             <wsdl:documentation
346                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
347                 <br />
348                 <h3>获得中国省份、直辖市、地区和与之对应的ID</h3>
349                 <p>输入参数:无,返回数据:一维字符串数组。</p>
350                 <br />
351             </wsdl:documentation>
352             <wsdl:input message="tns:getRegionProvinceHttpGetIn" />
353             <wsdl:output message="tns:getRegionProvinceHttpGetOut" />
354         </wsdl:operation>
355         <wsdl:operation name="getRegionCountry">
356             <wsdl:documentation
357                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
358                 <br />
359                 <h3>获得国外国家名称和与之对应的ID</h3>
360                 <p>输入参数:无,返回数据:一维字符串数组。</p>
361                 <br />
362             </wsdl:documentation>
363             <wsdl:input message="tns:getRegionCountryHttpGetIn" />
364             <wsdl:output message="tns:getRegionCountryHttpGetOut" />
365         </wsdl:operation>
366         <wsdl:operation name="getSupportCityDataset">
367             <wsdl:documentation
368                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
369                 <br />
370                 <h3>获得支持的城市/地区名称和与之对应的ID</h3>
371                 <p>输入参数:theRegionCode = 省市、国家ID或名称,返回数据:DataSet。</p>
372                 <br />
373             </wsdl:documentation>
374             <wsdl:input message="tns:getSupportCityDatasetHttpGetIn" />
375             <wsdl:output
376                 message="tns:getSupportCityDatasetHttpGetOut" />
377         </wsdl:operation>
378         <wsdl:operation name="getSupportCityString">
379             <wsdl:documentation
380                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
381                 <br />
382                 <h3>获得支持的城市/地区名称和与之对应的ID</h3>
383                 <p>输入参数:theRegionCode = 省市、国家ID或名称,返回数据:一维字符串数组。</p>
384                 <br />
385             </wsdl:documentation>
386             <wsdl:input message="tns:getSupportCityStringHttpGetIn" />
387             <wsdl:output message="tns:getSupportCityStringHttpGetOut" />
388         </wsdl:operation>
389         <wsdl:operation name="getWeather">
390             <wsdl:documentation
391                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
392                 <br />
393                 <h3>获得天气预报数据</h3>
394                 <p>输入参数:城市/地区ID或名称,返回数据:一维字符串数组。</p>
395                 <br />
396             </wsdl:documentation>
397             <wsdl:input message="tns:getWeatherHttpGetIn" />
398             <wsdl:output message="tns:getWeatherHttpGetOut" />
399         </wsdl:operation>
400     </wsdl:portType>
401     <wsdl:portType name="WeatherWSHttpPost">
402         <wsdl:operation name="getRegionDataset">
403             <wsdl:documentation
404                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
405                 <br />
406                 <h3>获得中国省份、直辖市、地区;国家名称(国外)和与之对应的ID</h3>
407                 <p>输入参数:无,返回数据:DataSet。</p>
408                 <br />
409             </wsdl:documentation>
410             <wsdl:input message="tns:getRegionDatasetHttpPostIn" />
411             <wsdl:output message="tns:getRegionDatasetHttpPostOut" />
412         </wsdl:operation>
413         <wsdl:operation name="getRegionProvince">
414             <wsdl:documentation
415                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
416                 <br />
417                 <h3>获得中国省份、直辖市、地区和与之对应的ID</h3>
418                 <p>输入参数:无,返回数据:一维字符串数组。</p>
419                 <br />
420             </wsdl:documentation>
421             <wsdl:input message="tns:getRegionProvinceHttpPostIn" />
422             <wsdl:output message="tns:getRegionProvinceHttpPostOut" />
423         </wsdl:operation>
424         <wsdl:operation name="getRegionCountry">
425             <wsdl:documentation
426                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
427                 <br />
428                 <h3>获得国外国家名称和与之对应的ID</h3>
429                 <p>输入参数:无,返回数据:一维字符串数组。</p>
430                 <br />
431             </wsdl:documentation>
432             <wsdl:input message="tns:getRegionCountryHttpPostIn" />
433             <wsdl:output message="tns:getRegionCountryHttpPostOut" />
434         </wsdl:operation>
435         <wsdl:operation name="getSupportCityDataset">
436             <wsdl:documentation
437                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
438                 <br />
439                 <h3>获得支持的城市/地区名称和与之对应的ID</h3>
440                 <p>输入参数:theRegionCode = 省市、国家ID或名称,返回数据:DataSet。</p>
441                 <br />
442             </wsdl:documentation>
443             <wsdl:input message="tns:getSupportCityDatasetHttpPostIn" />
444             <wsdl:output
445                 message="tns:getSupportCityDatasetHttpPostOut" />
446         </wsdl:operation>
447         <wsdl:operation name="getSupportCityString">
448             <wsdl:documentation
449                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
450                 <br />
451                 <h3>获得支持的城市/地区名称和与之对应的ID</h3>
452                 <p>输入参数:theRegionCode = 省市、国家ID或名称,返回数据:一维字符串数组。</p>
453                 <br />
454             </wsdl:documentation>
455             <wsdl:input message="tns:getSupportCityStringHttpPostIn" />
456             <wsdl:output
457                 message="tns:getSupportCityStringHttpPostOut" />
458         </wsdl:operation>
459         <wsdl:operation name="getWeather">
460             <wsdl:documentation
461                 xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
462                 <br />
463                 <h3>获得天气预报数据</h3>
464                 <p>输入参数:城市/地区ID或名称,返回数据:一维字符串数组。</p>
465                 <br />
466             </wsdl:documentation>
467             <wsdl:input message="tns:getWeatherHttpPostIn" />
468             <wsdl:output message="tns:getWeatherHttpPostOut" />
469         </wsdl:operation>
470     </wsdl:portType>
471     <wsdl:binding name="WeatherWSSoap"
472         type="tns:WeatherWSSoap">
473         <soap:binding
474             transport="http://schemas.xmlsoap.org/soap/http" />
475         <wsdl:operation name="getRegionDataset">
476             <soap:operation
477                 soapAction="http://WebXml.com.cn/getRegionDataset" style="document" />
478             <wsdl:input>
479                 <soap:body use="literal" />
480             </wsdl:input>
481             <wsdl:output>
482                 <soap:body use="literal" />
483             </wsdl:output>
484         </wsdl:operation>
485         <wsdl:operation name="getRegionProvince">
486             <soap:operation
487                 soapAction="http://WebXml.com.cn/getRegionProvince" style="document" />
488             <wsdl:input>
489                 <soap:body use="literal" />
490             </wsdl:input>
491             <wsdl:output>
492                 <soap:body use="literal" />
493             </wsdl:output>
494         </wsdl:operation>
495         <wsdl:operation name="getRegionCountry">
496             <soap:operation
497                 soapAction="http://WebXml.com.cn/getRegionCountry" style="document" />
498             <wsdl:input>
499                 <soap:body use="literal" />
500             </wsdl:input>
501             <wsdl:output>
502                 <soap:body use="literal" />
503             </wsdl:output>
504         </wsdl:operation>
505         <wsdl:operation name="getSupportCityDataset">
506             <soap:operation
507                 soapAction="http://WebXml.com.cn/getSupportCityDataset"
508                 style="document" />
509             <wsdl:input>
510                 <soap:body use="literal" />
511             </wsdl:input>
512             <wsdl:output>
513                 <soap:body use="literal" />
514             </wsdl:output>
515         </wsdl:operation>
516         <wsdl:operation name="getSupportCityString">
517             <soap:operation
518                 soapAction="http://WebXml.com.cn/getSupportCityString"
519                 style="document" />
520             <wsdl:input>
521                 <soap:body use="literal" />
522             </wsdl:input>
523             <wsdl:output>
524                 <soap:body use="literal" />
525             </wsdl:output>
526         </wsdl:operation>
527         <wsdl:operation name="getWeather">
528             <soap:operation
529                 soapAction="http://WebXml.com.cn/getWeather" style="document" />
530             <wsdl:input>
531                 <soap:body use="literal" />
532             </wsdl:input>
533             <wsdl:output>
534                 <soap:body use="literal" />
535             </wsdl:output>
536         </wsdl:operation>
537     </wsdl:binding>
538     <wsdl:binding name="WeatherWSSoap12"
539         type="tns:WeatherWSSoap">
540         <soap12:binding
541             transport="http://schemas.xmlsoap.org/soap/http" />
542         <wsdl:operation name="getRegionDataset">
543             <soap12:operation
544                 soapAction="http://WebXml.com.cn/getRegionDataset" style="document" />
545             <wsdl:input>
546                 <soap12:body use="literal" />
547             </wsdl:input>
548             <wsdl:output>
549                 <soap12:body use="literal" />
550             </wsdl:output>
551         </wsdl:operation>
552         <wsdl:operation name="getRegionProvince">
553             <soap12:operation
554                 soapAction="http://WebXml.com.cn/getRegionProvince" style="document" />
555             <wsdl:input>
556                 <soap12:body use="literal" />
557             </wsdl:input>
558             <wsdl:output>
559                 <soap12:body use="literal" />
560             </wsdl:output>
561         </wsdl:operation>
562         <wsdl:operation name="getRegionCountry">
563             <soap12:operation
564                 soapAction="http://WebXml.com.cn/getRegionCountry" style="document" />
565             <wsdl:input>
566                 <soap12:body use="literal" />
567             </wsdl:input>
568             <wsdl:output>
569                 <soap12:body use="literal" />
570             </wsdl:output>
571         </wsdl:operation>
572         <wsdl:operation name="getSupportCityDataset">
573             <soap12:operation
574                 soapAction="http://WebXml.com.cn/getSupportCityDataset"
575                 style="document" />
576             <wsdl:input>
577                 <soap12:body use="literal" />
578             </wsdl:input>
579             <wsdl:output>
580                 <soap12:body use="literal" />
581             </wsdl:output>
582         </wsdl:operation>
583         <wsdl:operation name="getSupportCityString">
584             <soap12:operation
585                 soapAction="http://WebXml.com.cn/getSupportCityString"
586                 style="document" />
587             <wsdl:input>
588                 <soap12:body use="literal" />
589             </wsdl:input>
590             <wsdl:output>
591                 <soap12:body use="literal" />
592             </wsdl:output>
593         </wsdl:operation>
594         <wsdl:operation name="getWeather">
595             <soap12:operation
596                 soapAction="http://WebXml.com.cn/getWeather" style="document" />
597             <wsdl:input>
598                 <soap12:body use="literal" />
599             </wsdl:input>
600             <wsdl:output>
601                 <soap12:body use="literal" />
602             </wsdl:output>
603         </wsdl:operation>
604     </wsdl:binding>
605     <wsdl:binding name="WeatherWSHttpGet"
606         type="tns:WeatherWSHttpGet">
607         <http:binding verb="GET" />
608         <wsdl:operation name="getRegionDataset">
609             <http:operation location="/getRegionDataset" />
610             <wsdl:input>
611                 <http:urlEncoded />
612             </wsdl:input>
613             <wsdl:output>
614                 <mime:mimeXml part="Body" />
615             </wsdl:output>
616         </wsdl:operation>
617         <wsdl:operation name="getRegionProvince">
618             <http:operation location="/getRegionProvince" />
619             <wsdl:input>
620                 <http:urlEncoded />
621             </wsdl:input>
622             <wsdl:output>
623                 <mime:mimeXml part="Body" />
624             </wsdl:output>
625         </wsdl:operation>
626         <wsdl:operation name="getRegionCountry">
627             <http:operation location="/getRegionCountry" />
628             <wsdl:input>
629                 <http:urlEncoded />
630             </wsdl:input>
631             <wsdl:output>
632                 <mime:mimeXml part="Body" />
633             </wsdl:output>
634         </wsdl:operation>
635         <wsdl:operation name="getSupportCityDataset">
636             <http:operation location="/getSupportCityDataset" />
637             <wsdl:input>
638                 <http:urlEncoded />
639             </wsdl:input>
640             <wsdl:output>
641                 <mime:mimeXml part="Body" />
642             </wsdl:output>
643         </wsdl:operation>
644         <wsdl:operation name="getSupportCityString">
645             <http:operation location="/getSupportCityString" />
646             <wsdl:input>
647                 <http:urlEncoded />
648             </wsdl:input>
649             <wsdl:output>
650                 <mime:mimeXml part="Body" />
651             </wsdl:output>
652         </wsdl:operation>
653         <wsdl:operation name="getWeather">
654             <http:operation location="/getWeather" />
655             <wsdl:input>
656                 <http:urlEncoded />
657             </wsdl:input>
658             <wsdl:output>
659                 <mime:mimeXml part="Body" />
660             </wsdl:output>
661         </wsdl:operation>
662     </wsdl:binding>
663     <wsdl:binding name="WeatherWSHttpPost"
664         type="tns:WeatherWSHttpPost">
665         <http:binding verb="POST" />
666         <wsdl:operation name="getRegionDataset">
667             <http:operation location="/getRegionDataset" />
668             <wsdl:input>
669                 <mime:content type="application/x-www-form-urlencoded" />
670             </wsdl:input>
671             <wsdl:output>
672                 <mime:mimeXml part="Body" />
673             </wsdl:output>
674         </wsdl:operation>
675         <wsdl:operation name="getRegionProvince">
676             <http:operation location="/getRegionProvince" />
677             <wsdl:input>
678                 <mime:content type="application/x-www-form-urlencoded" />
679             </wsdl:input>
680             <wsdl:output>
681                 <mime:mimeXml part="Body" />
682             </wsdl:output>
683         </wsdl:operation>
684         <wsdl:operation name="getRegionCountry">
685             <http:operation location="/getRegionCountry" />
686             <wsdl:input>
687                 <mime:content type="application/x-www-form-urlencoded" />
688             </wsdl:input>
689             <wsdl:output>
690                 <mime:mimeXml part="Body" />
691             </wsdl:output>
692         </wsdl:operation>
693         <wsdl:operation name="getSupportCityDataset">
694             <http:operation location="/getSupportCityDataset" />
695             <wsdl:input>
696                 <mime:content type="application/x-www-form-urlencoded" />
697             </wsdl:input>
698             <wsdl:output>
699                 <mime:mimeXml part="Body" />
700             </wsdl:output>
701         </wsdl:operation>
702         <wsdl:operation name="getSupportCityString">
703             <http:operation location="/getSupportCityString" />
704             <wsdl:input>
705                 <mime:content type="application/x-www-form-urlencoded" />
706             </wsdl:input>
707             <wsdl:output>
708                 <mime:mimeXml part="Body" />
709             </wsdl:output>
710         </wsdl:operation>
711         <wsdl:operation name="getWeather">
712             <http:operation location="/getWeather" />
713             <wsdl:input>
714                 <mime:content type="application/x-www-form-urlencoded" />
715             </wsdl:input>
716             <wsdl:output>
717                 <mime:mimeXml part="Body" />
718             </wsdl:output>
719         </wsdl:operation>
720     </wsdl:binding>
721     <wsdl:service name="WeatherWS">
722         <wsdl:documentation
723             xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
724             <a href="http://www.webxml.com.cn/" target="_blank">WebXml.com.cn</a>
725             <strong>2400多个城市天气预报Web服务</strong>
726             ,包含2300个以上中国城市和100个以上国外城市天气预报数据。数据每2.5小时左右自动更新一次,准确可靠。
727             <br />
728             使用本站 WEB 服务请注明或链接本站:
729             <a href="http://www.webxml.com.cn/" target="_blank">http://www.webxml.com.cn/</a>
730             感谢大家的支持!
731             <br />
732             <br />
733             <img alt="PDF" title="PDF file"
734                 src="http://www.webxml.com.cn/images/icon/pdf.gif"
735                 style="vertical-align: middle;" />
736             <a href="http://www.webxml.com.cn/files/WeatherWsHelp.pdf"
737                 target="_blank">接口帮助文档</a> &amp;nbsp;&amp;nbsp;&amp;nbsp;
738             <img alt="ZIP" title="ZIP file"
739                 src="http://www.webxml.com.cn/images/icon/zip.gif"
740                 style="vertical-align: middle;" />
741             <a href="http://www.webxml.com.cn/files/about_city.zip">部分城市介绍和气候背景</a> &amp;nbsp;&amp;nbsp;&amp;nbsp;
742             <img alt="ZIP" title="ZIP file"
743                 src="http://www.webxml.com.cn/images/icon/zip.gif"
744                 style="vertical-align: middle;" />
745             <a href="http://www.webxml.com.cn/files/city_photo.zip">部分城市图片</a> &amp;nbsp;&amp;nbsp;&amp;nbsp;
746             <img alt="HTML" title="HTML file"
747                 src="http://www.webxml.com.cn/images/icon/html.gif"
748                 style="vertical-align: middle;" />
749             <a href="http://www.webxml.com.cn/zh_cn/weather_icon.aspx"
750                 target="_blank">天气现象和图例</a>
751             <br />&amp;nbsp;
752         </wsdl:documentation>
753         <wsdl:port name="WeatherWSSoap" binding="tns:WeatherWSSoap">
754             <soap:address
755                 location="http://ws.webxml.com.cn/WebServices/WeatherWS.asmx" />
756         </wsdl:port>
757         <wsdl:port name="WeatherWSSoap12"
758             binding="tns:WeatherWSSoap12">
759             <soap12:address
760                 location="http://ws.webxml.com.cn/WebServices/WeatherWS.asmx" />
761         </wsdl:port>
762         <wsdl:port name="WeatherWSHttpGet"
763             binding="tns:WeatherWSHttpGet">
764             <http:address
765                 location="http://ws.webxml.com.cn/WebServices/WeatherWS.asmx" />
766         </wsdl:port>
767         <wsdl:port name="WeatherWSHttpPost"
768             binding="tns:WeatherWSHttpPost">
769             <http:address
770                 location="http://ws.webxml.com.cn/WebServices/WeatherWS.asmx" />
771         </wsdl:port>
772     </wsdl:service>
773 </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、创建开启客户端

 1 package cn.com.webxml;
 2 
 3 import java.net.MalformedURLException;
 4 import java.net.URL;
 5 import java.util.List;
 6 
 7 import javax.xml.namespace.QName;
 8 import javax.xml.ws.Service;
 9 
10 /**
11  * @desc 客户端
12  * @author xiaostudy
13  *
14  */
15 public class MyClient {
16 
17     public static void main(String[] args) {
18         //=============================================================================
19         //第一种方式获取视图
20         WeatherWS weatherWS = new WeatherWS();
21         //获取服务实现类
22         WeatherWSSoap weatherWSSoap = weatherWS.getPort(WeatherWSSoap.class);
23         //=============================================================================
24         
25         //=============================================================================
26         //第二种方式获取视图
27         /*URL url = null;
28         try {
29             url = new URL("http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl");
30         } catch (MalformedURLException e) {
31             e.printStackTrace();
32         }
33         
34         QName qName = new QName("http://WebXml.com.cn/", "WeatherWS");
35         
36         Service service = Service.create(url, qName);
37         WeatherWSSoap weatherWSSoap = service.getPort(WeatherWSSoap.class);*/
38         //=============================================================================
39         
40         //调用服务器接口,发送数据并返回数据
41         ArrayOfString arrayOfString = weatherWSSoap.getWeather("广州", "");
42         //控制台打印数据
43         List<String> list = arrayOfString.getString();
44         for(String str : list) {
45             System.out.println(str);
46         }
47     }
48 
49 }
MyClient.java
  1 package cn.com.webxml;
  2 
  3 import java.io.BufferedReader;
  4 import java.io.IOException;
  5 import java.io.InputStream;
  6 import java.io.InputStreamReader;
  7 import java.io.OutputStream;
  8 import java.net.HttpURLConnection;
  9 import java.net.MalformedURLException;
 10 import java.net.URL;
 11 
 12 /**
 13  * @desc 客户端
 14  * @author xiaostudy
 15  *
 16  */
 17 public class MyClient3 {
 18 
 19     public static void main(String[] args) {
 20         try {
 21             //第一步:创建服务地址,不是WSDL地址
 22             URL url = new URL("http://ws.webxml.com.cn/WebServices/WeatherWS.asmx");
 23             //第二步:打开一个通向服务地址的连接
 24             HttpURLConnection connection = (HttpURLConnection) url.openConnection();
 25             //第三步:设置参数
 26             //3.1发送方式设置:POST必须大写
 27             connection.setRequestMethod("POST");
 28             //3.2设置数据格式:content-type
 29             connection.setRequestProperty("content-type", "text/xml;charset=utf-8");
 30             //3.3设置输入输出,因为默认新创建的connection没有读写权限
 31             connection.setDoInput(true);
 32             connection.setDoOutput(true);
 33             //第四步:组织SOAP数据,发送请求
 34             String xml = getXml("广州");
 35             OutputStream os = connection.getOutputStream();
 36             os.write(xml.getBytes());
 37             //第五步:接收服务端响应,打印
 38             int responseCode = connection.getResponseCode();
 39             //5.1判断响应吗是否为200(200表示一切正常)
 40             if(responseCode == 200) {
 41                 //读取数据
 42                 InputStream is = connection.getInputStream();
 43                 //转化为字符流
 44                 InputStreamReader isr = new InputStreamReader(is);
 45                 //包装
 46                 BufferedReader br = new BufferedReader(isr);
 47                 StringBuffer sb = new StringBuffer();
 48                 String temp = null;
 49                 while(null != (temp = br.readLine())) {
 50                     sb.append(temp);
 51                 }
 52                 System.out.println(sb.toString());
 53                 
 54                 //关闭资源
 55                 if(is != null) {
 56                     is.close();
 57                     is = null;
 58                 }
 59                 if(isr != null) {
 60                     isr.close();
 61                     isr = null;
 62                 }
 63                 if(br != null) {
 64                     br.close();
 65                     br = null;
 66                 }
 67                 if(os != null) {
 68                     os.close();
 69                     os = null;
 70                 }
 71             }
 72         } catch (IOException e) {
 73             e.printStackTrace();
 74         }
 75         
 76         
 77     }
 78 
 79     /**
 80      * @desc 封装数据的方法
 81      * @param str 参数,城市名
 82      * @return String 返回类型,返回数据
 83      */
 84     private static String getXml(String str) {
 85         //前面两行和后面两行是固定格式,
 86         //<getWeather>是调用的方法
 87         //<theCityCode>和<theUserID>是调用方法里面的参数
 88         String soapXML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
 89                 +"<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/\">"
 90                   +"<soap:Body>"
 91                     +"<getWeather xmlns=\"http://WebXml.com.cn/\">"
 92                       +"<theCityCode>"+str+"</theCityCode>"
 93                       +"<theUserID></theUserID>"
 94                     +"</getWeather>"
 95                   +"</soap:Body>"
 96                 +"</soap:Envelope>";
 97                 return soapXML;
 98     }
 99 
100 }
MyClient3.java

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


 

转载于:https://www.cnblogs.com/xiaostudy/p/9570143.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值