ITeye博客

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

lee_xiaodong · 2010-04-02 17:59 · 编程语言 · Markdown

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

客户端采用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没有关系了

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。