您的位置:首页 > 其它

Web引用 查询手机归属地、城市天气

2011-12-21 11:44 288 查看
http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx 天气预报链接

http://hi.baidu.com/oritenson/blog/item/d8688d526bf45c0e377abe1f.html 手机号码归属地



添加web引用,将上面的网址Copy进去,



前台界面托几个控件如图



下面开始是后台代码:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

cn.com.webxml.www.WeatherWebService wws = new cn.com.webxml.www.WeatherWebService();

this.DropDownList1.DataSource = wws.getSupportProvince();

this.DropDownList1.DataBind();

}

}

protected void Button1_Click(object sender, EventArgs e)

{

weblocalhost.WebService ws = new weblocalhost.WebService();

this.GridView1.DataSource = ws.GetStudent();

this.GridView1.DataBind();

}

protected void Button2_Click(object sender, EventArgs e)

{

cn.com.webxml.www.WeatherWebService wws = new cn.com.webxml.www.WeatherWebService();

string[] strs = wws.getWeatherbyCityName(this.DropDownList2.SelectedValue);

this.Label1.Text = strs[0] + "," + strs[1] + "<br/>";

Label1.Text += "温度:" + strs[5] + "<br/>";

Label1.Text += "风:" + strs[7];

}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

{

cn.com.webxml.www.WeatherWebService wws = new cn.com.webxml.www.WeatherWebService();

BindCity(wws);

}

private void BindCity(cn.com.webxml.www.WeatherWebService wws)

{

this.DropDownList2.Items.Clear();

string[] strs = wws.getSupportCity(DropDownList1.SelectedValue);

foreach (string item in strs)

{

this.DropDownList2.Items.Add(new ListItem(item.Substring(0, item.IndexOf("("))));

}

}

protected void Button3_Click(object sender, EventArgs e)

{

cn.com.webxml.webservice.MobileCodeWS cww = new cn.com.webxml.webservice.MobileCodeWS();

this.Label2.Text = cww.getMobileCodeInfo(this.TextBox4.Text, "");

}

}

运行就可以实现天气和手机归属地的查询了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: