C#用天气预报的WebServices
后台代码:
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- WeatherWS ws = new WeatherWS();
- IList<string> provinceDataSource = new List<string>();
- DataSet proDs = ws.getRegionDataset();
- ddlProvince.DataSource = proDs.Tables[0].DefaultView;
- ddlProvince.DataTextField = "RegionName";
- ddlProvince.DataValueField = "RegionID";
- ddlProvince.DataBind();
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- WeatherWS ws = new WeatherWS();
- string [] wsInfo = ws.getWeather(ddlCity.SelectedValue,"");
- string result = string.Empty;
- for (int i = 0; i < wsInfo.Length; i++)
- {
- result += wsInfo[i]+"<BR/>";
- }
- Label1.Text = result;
- }
- protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
- {
- WeatherWS ws = new WeatherWS();
- DataSet cityDs = ws.getSupportCityDataset(ddlProvince.SelectedValue);
- ddlCity.DataSource = cityDs.Tables[0].DefaultView;
- ddlCity.DataTextField = "CityName";
- ddlCity.DataValueField = "CityID";
- ddlCity.DataBind();
- }
.aspx代码
- <asp:UpdatePanel ID="UpdatePanel1" runat="server">
- <ContentTemplate>
- <asp:DropDownList ID="ddlProvince" runat="server" AutoPostBack="True"
- onselectedindexchanged="ddlProvince_SelectedIndexChanged">
- </asp:DropDownList>
- <asp:DropDownList ID="ddlCity" runat="server">
- </asp:DropDownList>
- <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
- <br />
- <br />
- <br />
- <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
- </ContentTemplate>
- </asp:UpdatePanel>
访问速度很慢,,,...
第一步要添加Web引用
然后页面就有东西了.....webServices给的很明确了
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。