欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP.NET使用WebService實(shí)現(xiàn)天氣預(yù)報(bào)功能

 更新時(shí)間:2016年08月19日 16:49:14   作者:小飛飛oo  
這篇文章主要為大家詳細(xì)介紹了ASP.NET使用WebService實(shí)現(xiàn)天氣預(yù)報(bào)功能的相關(guān)資料,感興趣的小伙伴們可以參考一下

本文使用Asp.Net (C#)調(diào)用互聯(lián)網(wǎng)上公開的WebServices(http://www.webxml.com.cn/WebServices/WeatherWebService.asmx)來實(shí)現(xiàn)天氣預(yù)報(bào),該天氣預(yù)報(bào) Web 服務(wù),數(shù)據(jù)來源于中國氣象局http://www.cma.gov.cn/,數(shù)據(jù)每2.5小時(shí)左右自動(dòng)更新一次,準(zhǔn)確可靠。包括 340 多個(gè)中國主要城市和 60 多個(gè)國外主要城市三日內(nèi)的天氣預(yù)報(bào)數(shù)據(jù)。

效果圖 :

步驟 :

1 、新建web 項(xiàng)目,添加窗體。

2 、 引用右鍵--> 添加服務(wù)引用-->高級--> 添加Web引用。

3 、 將Web接口復(fù)制到URL右邊的框里-->點(diǎn)擊輸入框右邊的箭頭,測試連接(觀察左下角看是否連接成功)--> 最右邊可以更改Web引用名-->添加引用。

前臺(tái)代碼

<div>
 
 <br />
 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Asp.Net 調(diào)用WebService實(shí)現(xiàn)天氣預(yù)報(bào)<br />
 <br />
 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 請輸入城市名稱:<asp:TextBox ID="txtcity" runat="server"></asp:TextBox>
&nbsp;&nbsp;
 <asp:Label ID="Label1" runat="server" style="color: red" BorderColor="Red" Text="如 :上海"></asp:Label>
 <br />
 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <asp:Button ID="btncheck" runat="server" Text="查詢" Width="69px" OnClick="btncheck_Click" />
&nbsp;
 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 天氣概況 : <asp:Label ID="lbtianqi" runat="server" style="" BorderColor="Red" Text=""></asp:Label>
 <br />
 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 天氣實(shí)況 :&nbsp;&nbsp; 
 <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <asp:TextBox ID="txtcityweather" runat="server" Height="62px" TextMode="MultiLine" Width="258px"></asp:TextBox>
&nbsp;&nbsp;
 <br />
 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <br />
 <br />
 <br />
 <br />
 <br />
 <br />
 
 </div>

后臺(tái)代碼

protected void btncheck_Click(object sender, EventArgs e)
 {
  WeatherService.WeatherWebService w = new WeatherService.WeatherWebService();
  string [] res=new string[23];
  string cityname = txtcity.Text.Trim();
  res = w.getWeatherbyCityName(cityname);
  lbtianqi.Text = cityname + " "+res[6];
  txtcityweather.Text = res[10];

 }

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論