A weather forecast program implemented using webservice

Source: Internet
Author: User
Today, I found a free weather forecast Web Service on the Internet, so I used C #2005 to do a weather forecast program called webservice, which can display weather images.
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 = {'fig', '1', '=', '= '};
Char [] trim2 = {'fig', '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_vilet.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 ("input city Error or network Error", "Error", MessageBoxButtons. OK, MessageBoxIcon. Error );
MessageBox. Show (oe. Message );
}



}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.