首先要引用这个服务,http://www.webxml.com.cn/Webservices/WeatherWebService.asmx
出现对话框后,把中央气象的服务网址添加到里面
选择高级,
添加Web引用
添加引用就可以了,看好引用命名空间。
lick(object sender, EventArgs e)
{
cn.com.webxml.www.WeatherWebService w = new cn.com.webxml.www.WeatherWebService();
//把webservice当做一个类来操作
string[] s = new string[23];//声明string数组存放返回结果
string city = this.textBox1.Text.Trim();//获得文本框录入的查询城市
s = w.getWeatherbyCityName(city);
//for (int i = 0; i < s.Length; i++)
//{
// MessageBox.Show(s[i]);
//}
//以文本框内容为变量实现方法getWeatherbyCityName
if (s[8] == "")
{
MessageBox.Show("暂时不支持您查询的城市");
}
else
{
this.labgaikresual.Text= s[1] + " " + s[6];
labshikresual.Text = s[10];
//图片放到下面,s[8]是接口提供了 这个图片的名称为8.jpg 加上的话刚好是
D:/image/8.jpg 获得了图片的路径。
pictureBox1.Image=Image.fromfile(@“D:/image/”+s[8]+"")
}
}
w.getWeatherbyCityName(city) 返回的是一维数组,23个元素,每个元素你可以看下,messAgeBox.show 下 想要哪个?