今天在网上找到了一个免费的天气预报的webservice,于是就用C#2005做了一个调用webservice的天气预报的程序,可以显示天气图片的。
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Text;
using
System.Windows.Forms;
using
System.Net;
using
System.IO;
![None.gif](/Images/OutliningIndicators/None.gif)
namespace
WSWeather
![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
public partial class Form1 : Form
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
public Form1()
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
InitializeComponent();
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
private void Form1_Load(object sender, EventArgs e)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
}
![InBlock.gif](/Images/OutliningIndicators/InBlock.gif)
private void btn_ok_Click(object sender, EventArgs e)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
try
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
com.wopos.www.Weather w = new WSWeather.com.wopos.www.Weather();
string s = w.getWeather(this.cb_city.SelectedItem.ToString().Trim());
string[] temp;
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
char[] split =
{ ',' };
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
char[] trim1 =
{ '图', '1', '=', '=' };
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
char[] trim2 =
{ '图', '2', '=', '=' };
temp = s.Split(split);
this.lb_city.Text = temp[0];
this.lb_date.Text = temp[1];
this.lb_temper.Text = temp[5];
this.lb_weather.Text = temp[4];
this.lb_wind.Text = temp[6];
this.lb_violet.Text = temp[7];
WebRequest request1 = WebRequest.Create(temp[2].TrimStart(trim1));
WebRequest request2 = WebRequest.Create(temp[3].TrimStart(trim2));
request1.Credentials = CredentialCache.DefaultCredentials;
request2.Credentials = CredentialCache.DefaultCredentials;
HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
HttpWebResponse response2 = (HttpWebResponse)request2.GetResponse();
Stream imagestream1 = response1.GetResponseStream();
Stream imagestream2 = response2.GetResponseStream();
Image im1 = Image.FromStream(imagestream1, true, true);
Image im2 = Image.FromStream(imagestream2, true, true);
this.pb_image1.Image = im1;
this.pb_image2.Image = im2;
}
catch (Exception oe)
![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
// MessageBox.Show("输入城市错误或网络错误","错误",MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(oe.Message);
}
}
}
}