首先要引用這個服務,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 下 想要哪個?