Generated Image

做个天气预报的小例子

引用别人的WebServices

http://www.ayandy.com/

本服务数据来源于中国气象局数据,实时更新,准确可靠,包括国内外400多个主要城市。请不要用于任何商业目的,若有需要请与作者联系,欢迎技术交流。作者QQ:15244833 E-Mail:secretary@ayandy.com

The following operations are supported. For a formal definition, please review the Service Description.

  • getSupportCity
    查询本天气WebService支持的城市信息。输入参数: byProvinceName 指定的省份,若为ALL则表示全部。返回数据:一个二维数组String[],String[0]为返回的个数。
  • getSupportProvince
    查询本天气WebService支持的省份信息。输入参数: 无。 返回数据:一个二维数组String[],String[0]为返回的个数。
  • getWeatherbyCityName
    根据城市名称获得天气情况。调用方法如下:输入参数: theCityName 城市中文名称,如深圳,北京; theDayFlag 指定是当天(1),明天(2)或后天(3),可查询未来三天的天气情况;返回数据: String[7] 一个一维数值,共有七个元素,从[1]到[6]分别表示城市,天气,温度,风向,日期,天气图标地址。

 

看下代码

 

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Web.Services;
using Fxrl.com.ayandy.www;
  
namespace Fxrl
{
    public partial class WebService1 : Form
    {
        public WebService1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            com.ayandy.www.Service obj = new Service();
 
 
            string[] a1 = new string[10];
            try
            {
                a1 = obj.getWeatherbyCityName(textBox1.Text, com.ayandy.www.theDayFlagEnum.Today);
                label1.Text = a1[1].ToString();
                label2.Text = a1[2].ToString();
                label3.Text = a1[3].ToString();
                label4.Text = a1[4].ToString();
                label5.Text = a1[5].ToString();
                pictureBox1.ImageLocation = a1[6].ToString();
            }
            catch { }
        } 
    }
}

posted @ 2007-03-15 15:11  桂圆  阅读(1013)  评论(0)    收藏  举报