添加引用: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
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
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
// Response.Write(mystr[8]+"
");
//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代码: