天气预报的web服务的使用
2013-10-12 16:07
429 查看
添加Web引用:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
重命名为:weather
public string[] GetWeather(string city)
{
weather.WeatherWebService webweather = new
cheshi.weather.WeatherWebService();//实例化天气的服务
string[] wcity = webweather.getWeatherbyCityName(city);
return wcity;
}
private void weathers_Shown(object sender, EventArgs e)
{
try
{
weather.WeatherWebService wweather = new
cheshi.weather.WeatherWebService();
string[] area = wweather.getSupportProvince();
int mount = area.Length - 1;
comboBox1.Items.Clear();
for (int im = 0; im < mount; im++)
{
comboBox1.Items.Add(area[im].ToString());
}
comboBox1.SelectedIndex = 0;
}
catch { }
}
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
try
{
weather.WeatherWebService weweather = new
cheshi.weather.WeatherWebService();
string[] mcity = weweather.getSupportCity(comboBox1.Text);
int mcount = mcity.Length - 1;
comboBox2.Items.Clear();
for (int i = 0; i < mcount; i++)
{
comboBox2.Items.Add(mcity[i].Remove(mcity[i].IndexOf("(")));
}
comboBox2.SelectedIndex = 0;
}
catch { }
}
private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{
try
{
string[] cityweather =
GetWeather(comboBox2.Items[comboBox2.SelectedIndex].ToString());
label1.Text = cityweather[0].ToString();
label2.Text = cityweather[1].ToString();
label3.Text = cityweather[10].ToString();
//今天
pictureBox1.ImageLocation =@"images/weather/"
+cityweather[8].ToString();
pictureBox2.ImageLocation = @"images/weather/" +
cityweather[9].ToString();
label4.Text = cityweather[6].ToString() + cityweather[5].ToString()
+ cityweather[7].ToString();
label5.Text = cityweather[11].ToString();
//明天
label6.Text = cityweather[13].ToString() +
cityweather[12].ToString() + cityweather[14].ToString();
//后天
label7.Text = cityweather[18].ToString() +
cityweather[17].ToString() + cityweather[19].ToString();
//城市说明及图片
pictureBox3.ImageLocation = @"http://www.cma.gov.cn/tqyb/img/city/"
+ cityweather[3].ToString();
label8.Text = cityweather[22].ToString();
//预计时间
label9.Text = "预报时间:" + cityweather[4].ToString();
}
catch { }
}
重命名为:weather
public string[] GetWeather(string city)
{
weather.WeatherWebService webweather = new
cheshi.weather.WeatherWebService();//实例化天气的服务
string[] wcity = webweather.getWeatherbyCityName(city);
return wcity;
}
private void weathers_Shown(object sender, EventArgs e)
{
try
{
weather.WeatherWebService wweather = new
cheshi.weather.WeatherWebService();
string[] area = wweather.getSupportProvince();
int mount = area.Length - 1;
comboBox1.Items.Clear();
for (int im = 0; im < mount; im++)
{
comboBox1.Items.Add(area[im].ToString());
}
comboBox1.SelectedIndex = 0;
}
catch { }
}
private void comboBox1_SelectedIndexChanged(object sender,
EventArgs e)
{
try
{
weather.WeatherWebService weweather = new
cheshi.weather.WeatherWebService();
string[] mcity = weweather.getSupportCity(comboBox1.Text);
int mcount = mcity.Length - 1;
comboBox2.Items.Clear();
for (int i = 0; i < mcount; i++)
{
comboBox2.Items.Add(mcity[i].Remove(mcity[i].IndexOf("(")));
}
comboBox2.SelectedIndex = 0;
}
catch { }
}
private void comboBox2_SelectedIndexChanged(object sender,
EventArgs e)
{
try
{
string[] cityweather =
GetWeather(comboBox2.Items[comboBox2.SelectedIndex].ToString());
label1.Text = cityweather[0].ToString();
label2.Text = cityweather[1].ToString();
label3.Text = cityweather[10].ToString();
//今天
pictureBox1.ImageLocation =@"images/weather/"
+cityweather[8].ToString();
pictureBox2.ImageLocation = @"images/weather/" +
cityweather[9].ToString();
label4.Text = cityweather[6].ToString() + cityweather[5].ToString()
+ cityweather[7].ToString();
label5.Text = cityweather[11].ToString();
//明天
label6.Text = cityweather[13].ToString() +
cityweather[12].ToString() + cityweather[14].ToString();
//后天
label7.Text = cityweather[18].ToString() +
cityweather[17].ToString() + cityweather[19].ToString();
//城市说明及图片
pictureBox3.ImageLocation = @"http://www.cma.gov.cn/tqyb/img/city/"
+ cityweather[3].ToString();
label8.Text = cityweather[22].ToString();
//预计时间
label9.Text = "预报时间:" + cityweather[4].ToString();
}
catch { }
}
相关文章推荐
- 天气预报web服务使用
- Web Service学习笔记:天气预报Web服务的使用方法
- 使用WebRequest对象调用新浪天气预报<转>
- 利用WEB服务在网页中插入天气预报功能
- Android使用WebView来显示天气预报
- 天气预报 Web 服务
- 用.Net的Web服务实现天气预报
- 天气预报 Web 服务
- 天气预报 Web 服务
- Android天气预报,手机号码归属地,股市行情WEB服务 webservice
- 使用SAX解析XML利用Google Weather服务制作天气预报异常解决办法
- 完整的天气预报web服务源码
- Web服务入门之二:通过axis2调用远程Web Service,实现天气预报功能
- 针对中国地区的天气预报服务,包括: 查询天气预报的Web站点:http://weather-china.appspot.com/ 基于JSON的REST API接口
- 针对中国地区的天气预报服务,包括: 查询天气预报的Web站点:http://weather-china.appspot.com/ 基于JSON的REST API接口
- VBOX使用NAT端口转发实现宿主机器访问genymotion上的web服务
- 使用asp.net开发天气预报程序
- 在.NET框架的Web服务上使用Base64编码
- 使用 Flex 开发 Web 服务客户端
- 使用 Spring 3 MVC HttpMessageConverter 功能构建 RESTful web 服务