加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

调用天气预报WebService

发布时间:2020-12-17 00:43:31 所属栏目:安全 来源:网络整理
导读:添加引用:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx .cs代码: ?WeatherWebServiceSoap w = new WeatherWebServiceSoapClient("WeatherWebServiceSoap"); ??????? protected void Page_Load(object sender,EventArgs e) ??????? { ????

添加引用:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx

.cs代码:

?WeatherWebServiceSoap w = new WeatherWebServiceSoapClient("WeatherWebServiceSoap");
??????? protected void Page_Load(object sender,EventArgs e)
??????? {
??????????? if (!IsPostBack)
??????????? {
??????????????? BindPro();
??????????????? BindCity();
??????????? }
??????? }
??????? //province
??????? protected void BindPro()
??????? {
??????????? string[] pro = w.getSupportProvince();
??????????? for (int i = 0; i < pro.Length; i++)
??????????? {
??????????????? ddlProv.Items.Add(new ListItem(pro[i],pro[i]));
??????????? }
??????? }
??????? //city
??????? protected void BindCity()
??????? {
??????????? ddlCity.Items.Clear();
??????????? string[] city = w.getSupportCity(ddlProv.SelectedValue);
??????????? for (int i = 0; i < city.Length; i++)
??????????? {
??????????????? ddlCity.Items.Add(new ListItem(city[i],city[i]));
??????????? }
??????? }
??????? //weather
??????? protected void BindWeather()
??????? {
??????????? string city = ddlCity.SelectedValue.ToString().Substring(0,2);
??????????? //Response.Write(city);
??????????? string[] mystr = w.getWeatherbyCityName(city);
??????????? //for (int i = 0; i < mystr.Length; i++)
??????????? //{
??????????? //? Response.Write(mystr[8]+"<br/>");
????????????? //img.ImageUrl = "images/a_" + mystr[8];
??????????? //}
????????????? //mystr[0] 省
????????????? //mystr[2] 城市后的代码
???????????
??????????? labCity.Text = mystr[1];//城市
??????????? Label2.Text = mystr[6];//日期+天气情况(如:7月4日 多云)
??????????? Label3.Text = mystr[5];//温度(如:28℃/34℃)
??????????? Label4.Text = mystr[4];//时间(如:2012-7-4 12:04:38)
??????? }

??????? protected void ddlProv_SelectedIndexChanged(object sender,EventArgs e)
??????? {
??????????? BindCity();
??????? }

??????? protected void Button1_Click(object sender,EventArgs e)
??????? {
??????????? BindWeather();
??????? }

?

html代码:

<body> ??? <form id="form1" runat="server"> ??? <div> ??????? <asp:DropDownList ID="ddlProv" runat="server" AutoPostBack="True" onselectedindexchanged="ddlProv_SelectedIndexChanged"></asp:DropDownList> ??????? <asp:DropDownList ID="ddlCity" runat="server"></asp:DropDownList> ??????? <asp:Label ID="labCity" runat="server" Text="Label"></asp:Label> ??????? <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label> ??????? <asp:Label ID="Label3" runat="server" Text="Label"></asp:Label> ??????? <asp:Label ID="Label4" runat="server" Text="Label"></asp:Label> ??????? <br /> ??????? <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="获 取" /> ??? </div> ??? </form> </body>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读