新建WinForm 项目;
点击添加服务引用》点击高级》点击添加Web引用:在URl输入http://www.webxml.com.cn/WebServices/WeatherWebService.asmx,点击转到,点击添加引用
按钮点击事件:
/// <summary>
/// 获取天气
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
cn.com.webxml.www.WeatherWebService w = new cn.com.webxml.www.WeatherWebService();
string[] s = new string[23];//声明string数组存放返回结果
string city = this.textBox1.Text.Trim();//获得文本框录入的查询城市
s = w.getWeatherbyCityName(city);
if (s[8] == "")
{
// MessageBox.Show("输入错误,请重新输入", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
}
else
{
textBox2.Text = s[1] + " " + s[6]+ s[10];
}
}
效果: