我们通过下面的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>
客户端采用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>