下面這個位址是一個比較穩定的擷取天氣情況的WebService:
<a href="http://www.webxml.com.cn/WebServices/WeatherWebService.asmx">http://www.webxml.com.cn/WebServices/WeatherWebService.asmx </a>
這裡用到裡面的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>
<asp:Image ID="imgTQPicture" runat="server" />
<asp:Label ID="lblTQ2" runat="server"></asp:Label>
</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();
補充接口位址: