用webservice实现的一个天气预报程序

     今天在网上找到了一个免费的天气预报的webservice,于是就用C#2005做了一个调用webservice的天气预报的程序,可以显示天气图片的。
 
None.gif using  System;
None.gif
using  System.Collections.Generic;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Text;
None.gif
using  System.Windows.Forms;
None.gif
using  System.Net;
None.gif
using  System.IO;
None.gif
None.gif
namespace  WSWeather
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public partial class Form1 : Form
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public Form1()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            InitializeComponent();
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void Form1_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private void btn_ok_Click(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                com.wopos.www.Weather w 
= new WSWeather.com.wopos.www.Weather();
InBlock.gif                
string s = w.getWeather(this.cb_city.SelectedItem.ToString().Trim());
InBlock.gif                
string[] temp;
ExpandedSubBlockStart.gifContractedSubBlock.gif                
char[] split =dot.gif',' };
ExpandedSubBlockStart.gifContractedSubBlock.gif                
char[] trim1 =dot.gif'''1''=''=' };
ExpandedSubBlockStart.gifContractedSubBlock.gif                
char[] trim2 =dot.gif'''2''=''=' };
InBlock.gif                temp 
= s.Split(split);
InBlock.gif                
this.lb_city.Text = temp[0];
InBlock.gif                
this.lb_date.Text = temp[1];
InBlock.gif                
this.lb_temper.Text = temp[5];
InBlock.gif                
this.lb_weather.Text = temp[4];
InBlock.gif                
this.lb_wind.Text = temp[6];
InBlock.gif                
this.lb_violet.Text = temp[7];
InBlock.gif                WebRequest request1 
= WebRequest.Create(temp[2].TrimStart(trim1));
InBlock.gif                WebRequest request2 
= WebRequest.Create(temp[3].TrimStart(trim2));
InBlock.gif                request1.Credentials 
= CredentialCache.DefaultCredentials;
InBlock.gif                request2.Credentials 
= CredentialCache.DefaultCredentials;
InBlock.gif                HttpWebResponse response1 
= (HttpWebResponse)request1.GetResponse();
InBlock.gif                HttpWebResponse response2 
= (HttpWebResponse)request2.GetResponse();
InBlock.gif                Stream imagestream1 
= response1.GetResponseStream();
InBlock.gif                Stream imagestream2 
= response2.GetResponseStream();
InBlock.gif                Image im1 
= Image.FromStream(imagestream1, truetrue);
InBlock.gif                Image im2 
= Image.FromStream(imagestream2, truetrue);
InBlock.gif                
this.pb_image1.Image = im1;
InBlock.gif                
this.pb_image2.Image = im2;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception oe)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif               
// MessageBox.Show("输入城市错误或网络错误","错误",MessageBoxButtons.OK, MessageBoxIcon.Error);
InBlock.gif
                MessageBox.Show(oe.Message);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
InBlock.gif           
InBlock.gif            
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值