下面这个地址是一个比较稳定的获取天气情况的WebService:
http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
这里用到里面的getWeatherbyCityName方法
(1)、首先添加服务引用 ,添加webservices的引用地址:
http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
给起个名称为getWeather
(2)、在该网站下下载气象图片,将下载的weather文件夹放在网站根目录下的images文件夹下。
(3)、编写代码,获取信息:
<table width="100%"> <tr> <td style="width:10%"> <img src="images/rq.png" mce_src="images/rq.png" width="15" height="14" alt="" /> </td> <td > <asp:Label ID="lblTQ1" runat="server"></asp:Label> </td> <td > <asp:Image ID="imgTQPicture" runat="server" /> </td> <td > <asp:Label ID="lblTQ2" runat="server"></asp:Label> </td> </tr> </table> //调用WebService,返回天气信息 WeatherWebServiceSoapClient client = new WeatherWebServiceSoapClient("WeatherWebServiceSoap"); string[] weatherArray = new string[23]; string[] str = new string[23]; str = client.getWeatherbyCityName("合肥"); StringBuilder sb = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); sb.Append("今天是"); sb.Append(DateTime.Parse(str[4]).ToString("yyyy年MM月dd日")); sb2.Append(str[1]); sb2.Append(str[6].Substring(str[6].IndexOf(' '))); sb2.Append(str[5]); this.lblTQ1.Text = sb.ToString(); this.imgTQPicture.ImageUrl = @"images/weather/" + str[8]; this.lblTQ2.Text = sb2.ToString();
补充接口地址:
1、http://webservice.36wu.com/weatherService.asmx