C#用天气预报的WebServices

后台代码: 

C#代码  
  1. protected void Page_Load(object sender, EventArgs e)  
  2.    {  
  3.        if (!IsPostBack)  
  4.        {  
  5.            WeatherWS ws = new WeatherWS();  
  6.            IList<string> provinceDataSource = new List<string>();  
  7.   
  8.            DataSet proDs = ws.getRegionDataset();  
  9.            ddlProvince.DataSource = proDs.Tables[0].DefaultView;  
  10.            ddlProvince.DataTextField = "RegionName";  
  11.            ddlProvince.DataValueField = "RegionID";  
  12.            ddlProvince.DataBind();  
  13.        }  
  14.    }  
  15.   
  16.    protected void Button1_Click(object sender, EventArgs e)  
  17.    {  
  18.   
  19.        WeatherWS ws = new WeatherWS();  
  20.        string [] wsInfo = ws.getWeather(ddlCity.SelectedValue,"");  
  21.        string result = string.Empty;  
  22.        for (int i = 0; i < wsInfo.Length; i++)  
  23.        {  
  24.            result += wsInfo[i]+"<BR/>";  
  25.        }  
  26.        Label1.Text = result;  
  27.   
  28.    }  
  29.   
  30.    protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)  
  31.    {  
  32.        WeatherWS ws = new WeatherWS();  
  33.        DataSet cityDs = ws.getSupportCityDataset(ddlProvince.SelectedValue);  
  34.        ddlCity.DataSource = cityDs.Tables[0].DefaultView;  
  35.        ddlCity.DataTextField = "CityName";  
  36.        ddlCity.DataValueField = "CityID";  
  37.        ddlCity.DataBind();  
  38.    }  

 .aspx代码 

C#代码  
  1. <asp:UpdatePanel ID="UpdatePanel1" runat="server">  
  2.                 <ContentTemplate>  
  3.                     <asp:DropDownList ID="ddlProvince" runat="server" AutoPostBack="True"   
  4.                         onselectedindexchanged="ddlProvince_SelectedIndexChanged">  
  5.                     </asp:DropDownList>  
  6.                     <asp:DropDownList ID="ddlCity" runat="server">  
  7.                     </asp:DropDownList>  
  8.                     <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />  
  9.                     <br />  
  10.                     <br />  
  11.                     <br />  
  12.                     <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>  
  13.                 </ContentTemplate>  
  14.             </asp:UpdatePanel>  

 访问速度很慢,,,... 

第一步要添加Web引用

 

 

然后页面就有东西了.....webServices给的很明确了

C#用天气预报的WebServices,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。