C#用天气预报的WebServices
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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给的很明确了
以上是关于C#用天气预报的WebServices的主要内容,如果未能解决你的问题,请参考以下文章