
C#编写WinForm调用WeatherWebService教程.doc
5星
- 浏览量: 0
- 大小:None
- 文件类型:DOC
简介:
本文档提供了一步一步的教学指南,详细介绍如何使用C#编程语言在Windows Forms应用程序中集成并调用天气Web服务。适合希望掌握此技能以增强其软件开发能力的学习者和开发者阅读。
在 `button1_Click` 方法中调用了一个名为 `WeatherWebServiceSoapClient` 的 Web 服务客户端对象,并将其初始化为一个特定的实例。声明一个包含23个元素的字符串数组来存储从Web服务返回的结果。
获取文本框2中的内容并保存到变量 `c` 中,然后使用该变量作为参数调用方法 `getWeatherbyCityName()` 来查询天气信息并将结果存入数组 `s` 中:
```C#
private void button1_Click(object sender, EventArgs e)
{
weathertest.Weather.WeatherWebServiceSoapClient w = new weathertest.Weather.WeatherWebServiceSoapClient(WeatherWebServiceSoap);
string[] s = new string[23];
string c = this.textBox2.Text.Trim();
s = w.getWeatherbyCityName(c);
if (s[8] == )
{
MessageBox.Show(暂时不支持您查询的城市);
}
else
{
pictureBox1.Image = Image.FromFile(@d:image\ + s[8]);
// 将数组中的值赋给相应的文本框显示出来:
textBox1.Text = s[0];
textBox3.Text = s[1];
textBox4.Text = s[2];
textBox5.Text = s[4];
textBox6.Text = s[5];
textBox7.Text = s[6];
textBox8.Text = s[7];
textBox9.Text = s[10];
textBox10.Text = s[12];
textBox11.Text = s[13];
textBox12.Text = s[14];
textBox13.Text = s[17];
textBox14.Text = s[18];
textBox15.Text = s[19];
}
}
```
全部评论 (0)


