C#调用WebService制作天气预报
2014-03-17 16:23
519 查看
目前基于互联网的编程新兴起面向服务的编程,即通过Web中网站提供的服务接口进行编程。
下面介绍一个调用WebService制作天气预报的方法:
添加Web引用:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 天气助手
{
public partial class Weather : Form
{
public Weather()
{
InitializeComponent();
}
public string[] GetWeather(string xCity)
{
cn.com.webxml.www.WeatherWebService mWeatherWebService = new cn.com.webxml.www.WeatherWebService();
string[] WeatherOfCity = mWeatherWebService.getWeatherbyCityName(xCity);
return WeatherOfCity;
}
private void Weather_Load(object sender, EventArgs e)
{
}
public void Weather_Shown(object sender, EventArgs e)
{
try
{
cn.com.webxml.www.WeatherWebService mWeatherWebService = new cn.com.webxml.www.WeatherWebService();
string[] mArea = mWeatherWebService.getSupportProvince();
int mCount = mArea.Length - 1;
comboBox01.Items.Clear();
for (int mI = 0; mI <= mCount; mI++)
{
comboBox01.Items.Add(mArea[mI].ToString());
}
comboBox01.SelectedIndex = 0;
}
catch
{
}
}
public void comboBox01_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
cn.com.webxml.www.WeatherWebService mWeatherWebService = new cn.com.webxml.www.WeatherWebService();
string[] mCity = mWeatherWebService.getSupportCity(comboBox01.Text);
int mCount = mCity.Length - 1;
comboBox02.Items.Clear();
for (int mI = 0; mI <= mCount; mI++)
{
comboBox02.Items.Add(mCity[mI].Remove(mCity[mI].IndexOf("(")));
}
comboBox02.SelectedIndex = 0;
}
catch
{
}
}
public void comboBox02_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
string[] WeatherOfCity = GetWeather(comboBox02.Items[comboBox02.SelectedIndex].ToString());
label03.Text = WeatherOfCity[0].ToString();
label05.Text = WeatherOfCity[1].ToString();
label06.Text = WeatherOfCity[10].ToString();
//今天
pictureBox01.ImageLocation = @"images/weather/" + WeatherOfCity[8].ToString();
pictureBox02.ImageLocation = @"images/weather/" + WeatherOfCity[9].ToString();
label07.Text = WeatherOfCity[6].ToString() + WeatherOfCity[5].ToString() + WeatherOfCity[7].ToString();
label08.Text = WeatherOfCity[11].ToString();
//明天
pictureBox03.ImageLocation = @"images/weather/" + WeatherOfCity[15].ToString();
pictureBox04.ImageLocation = @"images/weather/" + WeatherOfCity[16].ToString();
label16.Text = WeatherOfCity[13].ToString() + WeatherOfCity[12].ToString() + WeatherOfCity[14].ToString();
//后天
pictureBox05.ImageLocation = @"images/weather/" + WeatherOfCity[20].ToString();
pictureBox06.ImageLocation = @"images/weather/" + WeatherOfCity[21].ToString();
label17.Text = WeatherOfCity[18].ToString() + WeatherOfCity[17].ToString() + WeatherOfCity[19].ToString();
//城市说明及图片
pictureBox07.ImageLocation = @"http://www.cma.gov.cn/tqyb/img/city/" + WeatherOfCity[3].ToString();
label18.Text = WeatherOfCity[22].ToString();
//预计时间
label19.Text = "预报时间:" + WeatherOfCity[4].ToString();
}
catch
{
}
}
}
}
天气预报可调用实例下载:http://www.webxml.com.cn/files/weather_eg.zip
下面介绍一个调用WebService制作天气预报的方法:
添加Web引用:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 天气助手
{
public partial class Weather : Form
{
public Weather()
{
InitializeComponent();
}
public string[] GetWeather(string xCity)
{
cn.com.webxml.www.WeatherWebService mWeatherWebService = new cn.com.webxml.www.WeatherWebService();
string[] WeatherOfCity = mWeatherWebService.getWeatherbyCityName(xCity);
return WeatherOfCity;
}
private void Weather_Load(object sender, EventArgs e)
{
}
public void Weather_Shown(object sender, EventArgs e)
{
try
{
cn.com.webxml.www.WeatherWebService mWeatherWebService = new cn.com.webxml.www.WeatherWebService();
string[] mArea = mWeatherWebService.getSupportProvince();
int mCount = mArea.Length - 1;
comboBox01.Items.Clear();
for (int mI = 0; mI <= mCount; mI++)
{
comboBox01.Items.Add(mArea[mI].ToString());
}
comboBox01.SelectedIndex = 0;
}
catch
{
}
}
public void comboBox01_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
cn.com.webxml.www.WeatherWebService mWeatherWebService = new cn.com.webxml.www.WeatherWebService();
string[] mCity = mWeatherWebService.getSupportCity(comboBox01.Text);
int mCount = mCity.Length - 1;
comboBox02.Items.Clear();
for (int mI = 0; mI <= mCount; mI++)
{
comboBox02.Items.Add(mCity[mI].Remove(mCity[mI].IndexOf("(")));
}
comboBox02.SelectedIndex = 0;
}
catch
{
}
}
public void comboBox02_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
string[] WeatherOfCity = GetWeather(comboBox02.Items[comboBox02.SelectedIndex].ToString());
label03.Text = WeatherOfCity[0].ToString();
label05.Text = WeatherOfCity[1].ToString();
label06.Text = WeatherOfCity[10].ToString();
//今天
pictureBox01.ImageLocation = @"images/weather/" + WeatherOfCity[8].ToString();
pictureBox02.ImageLocation = @"images/weather/" + WeatherOfCity[9].ToString();
label07.Text = WeatherOfCity[6].ToString() + WeatherOfCity[5].ToString() + WeatherOfCity[7].ToString();
label08.Text = WeatherOfCity[11].ToString();
//明天
pictureBox03.ImageLocation = @"images/weather/" + WeatherOfCity[15].ToString();
pictureBox04.ImageLocation = @"images/weather/" + WeatherOfCity[16].ToString();
label16.Text = WeatherOfCity[13].ToString() + WeatherOfCity[12].ToString() + WeatherOfCity[14].ToString();
//后天
pictureBox05.ImageLocation = @"images/weather/" + WeatherOfCity[20].ToString();
pictureBox06.ImageLocation = @"images/weather/" + WeatherOfCity[21].ToString();
label17.Text = WeatherOfCity[18].ToString() + WeatherOfCity[17].ToString() + WeatherOfCity[19].ToString();
//城市说明及图片
pictureBox07.ImageLocation = @"http://www.cma.gov.cn/tqyb/img/city/" + WeatherOfCity[3].ToString();
label18.Text = WeatherOfCity[22].ToString();
//预计时间
label19.Text = "预报时间:" + WeatherOfCity[4].ToString();
}
catch
{
}
}
}
}
天气预报可调用实例下载:http://www.webxml.com.cn/files/weather_eg.zip
相关文章推荐
- 用C#写的winform调用webservice天气预报小软件教程
- C#调用WebService实现天气预报
- 用C#写的winform调用webservice天气预报小软件教程(转自百度文库)
- C#调用WebService实现天气预报
- C#调用WebService天气服务,实现天气预报
- C#调用WebService实现天气预报
- 用C#写的winform调用webservice天气预报小软件教程(转自百度文库)
- Android 通过WebService调用天气预报接口
- java调用WebService天气预报实例
- Java 调用webservice 实现天气预报
- webservices系列(三)——调用线上webservice(天气预报和号码查询)
- Flex 调用WEBService 接口实现天气预报功能.
- Android 通过WebService调用天气预报接口
- 调用对象[置顶] Android通过调用Webservice实现天气预报
- Android中ksoap2-android调用WebService 实现天气预报
- C#调用天气预报网络服务
- webservice 调用国内航班,天气预报 等外部接口
- C#添加WebService服务实现天气预报(查询)
- C#调用WebService制作天气预报
- C#调用WebService获取天气信息