基于webservice给网站提供天气信息

我们通过下面的URL获得天气信息:[url]http://www.webservicex.net/globalweather.asmx?WSDL[/url]

客户端采用myeclipse自动生成的方式:

具体操作如下:
new - Web Service -Web Service Client

选择自己的项目
Service Definition 选择
WSDL URL:http://www.webservicex.net/globalweather.asmx?WSDL

选择Java Source 和Java package

Finish之后

自动在Java package生成两个文件GlobalWeatherClient和GlobalWeatherSoap
一个包net.webservicex里面有
GetCitiesByCountry
GetCitiesByCountryResponse
GetWeather
GetWeatherResponse
ObjectFactory
package-info
几个类

打开GlobalWeatherClient类在 main 里添加 System.out.println(service.getCitiesByCountry("China"));
运行就可以从webservice获得China的所有城市,其他的获得某个城市天气预报函数也都通过GlobalWeatherSoap中相应函数调用就可以了.

返回的数据就是xml格式的,剩下的工作就是通过DOM解析xml显示到页面上了,跟webservice没有关系了


<NewDataSet>
<Table>
<Country>China</Country>
<City>Beijing</City>
</Table>
<Table>
<Country>China</Country>
<City>Hohhot</City>
</Table>
<Table>
<Country>China</Country>
<City>Tianjin / Zhangguizhu</City>
</Table>
<Table>
<Country>China</Country>
<City>Taiyuan</City>
</Table>
<Table>
<Country>China</Country>
<City>Changsha</City>
</Table>
<Table>
<Country>China</Country>
<City>Guangzhou</City>
</Table>
<Table>
<Country>China</Country>
<City>Haikou</City>
</Table>
<Table>
<Country>China</Country>
<City>Guilin</City>
</Table>
<Table>
<Country>China</Country>
<City>Nanning</City>
</Table>
<Table>
<Country>China</Country>
<City>Shantou</City>
</Table>
<Table>
<Country>China</Country>
<City>Shenzhen</City>
</Table>
<Table>
<Country>China</Country>
<City>Zhanjiang</City>
</Table>
<Table>
<Country>China</Country>
<City>Zhengzhou</City>
</Table>
<Table>
<Country>China</Country>
<City>Wuhan</City>
</Table>
<Table>
<Country>China</Country>
<City>Yinchuan</City>
</Table>
<Table>
<Country>China</Country>
<City>Jiuquan</City>
</Table>
<Table>
<Country>China</Country>
<City>Xi'An</City>
</Table>
<Table>
<Country>China</Country>
<City>Xining</City>
</Table>
<Table>
<Country>China</Country>
<City>Yan An</City>
</Table>
<Table>
<Country>China</Country>
<City>Kunming</City>
</Table>
<Table>
<Country>China</Country>
<City>Xiamen</City>
</Table>
<Table>
<Country>China</Country>
<City>Nanchang</City>
</Table>
<Table>
<Country>China</Country>
<City>Fuzhou</City>
</Table>
<Table>
<Country>China</Country>
<City>Ganzhou</City>
</Table>
<Table>
<Country>China</Country>
<City>Hangzhou</City>
</Table>
<Table>
<Country>China</Country>
<City>Nanjing</City>
</Table>
<Table>
<Country>China</Country>
<City>Hefei</City>
</Table>
<Table>
<Country>China</Country>
<City>Qingdao</City>
</Table>
<Table>
<Country>China</Country>
<City>Shanghai / Hongqiao</City>
</Table>
<Table>
<Country>China</Country>
<City>Jinan</City>
</Table>
<Table>
<Country>China</Country>
<City>Chongqing</City>
</Table>
<Table>
<Country>China</Country>
<City>Guiyang</City>
</Table>
<Table>
<Country>China</Country>
<City>Lhasa</City>
</Table>
<Table>
<Country>China</Country>
<City>Chengdu</City>
</Table>
<Table>
<Country>China</Country>
<City>Hami</City>
</Table>
<Table>
<Country>China</Country>
<City>Kashi</City>
</Table>
<Table>
<Country>China</Country>
<City>Hotan</City>
</Table>
<Table>
<Country>China</Country>
<City>Urum-Qi / Diwopu</City>
</Table>
<Table>
<Country>China</Country>
<City>Yining</City>
</Table>
<Table>
<Country>China</Country>
<City>Changchun</City>
</Table>
<Table>
<Country>China</Country>
<City>Qiqihar</City>
</Table>
<Table>
<Country>China</Country>
<City>Dalian</City>
</Table>
</NewDataSet>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值