今天在网上找到了一个免费的天气预报的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;
namespace WSWeather
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btn_ok_Click(object sender, EventArgs e)
{
try
{
com.wopos.www.Weather w = new WSWeather.com.wopos.www.Weather();
string s = w.getWeather(this.cb_city.SelectedItem.ToString().Trim());
string[] temp;
char[] split ={ ',' };
char[] trim1 ={ '图', '1', '=', '=' };
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)
{
// MessageBox.Show("输入城市错误或网络错误","错误",MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(oe.Message);
}
}
}
}
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;
namespace WSWeather
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btn_ok_Click(object sender, EventArgs e)
{
try
{
com.wopos.www.Weather w = new WSWeather.com.wopos.www.Weather();
string s = w.getWeather(this.cb_city.SelectedItem.ToString().Trim());
string[] temp;
char[] split ={ ',' };
char[] trim1 ={ '图', '1', '=', '=' };
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)
{
// MessageBox.Show("输入城市错误或网络错误","错误",MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(oe.Message);
}
}
}
}