题目如上,我是个新手,代码实现上有些困难,总是会出现错误,希望
1,用代码实现获取天气信息,能告诉下思路(希望不是自己创建Webservice和网上的同步)
2,给出部分代码参考,代码格式多点更好!
3,如何在VS2008上生成XML格式,告诉下具体操作.
4,能够加Timer控件,3小时刷新下数据(方便的话就给)
在线等答案,谢谢帮助!

解决方案 »

  1.   

    http://www.webxml.com.cn/WebServices/WeatherWebService.asmx
    WeatherWebService wws = new WeatherWebService();
    string[] weatherArray = wws.getWeatherbyCityName("");
    Console.WriteLine("{0}-{1}-{2}", weatherArray[6], weatherArray[7], weatherArray[8]);
    Console.Read();
    htpwebrequest抓取天气数据
    System.Threading.Timer tUpdatefile = new System.Threading.Timer(new TimerCallback(test), null, 0, 3*60*60 * 1000);
     private void test(object source)
    {}
      

  2.   

    有部分没看懂 能QQ和你联系么~我QQ是349954464~
      

  3.   

    如果说WeatherWebService 缺少程序集引用,该怎么办?
      

  4.   

    我来补充一下,怎么使用这个WebService
    1. 添加Web引用:把这个WSDL拷贝到地址栏中:
    "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx"2. 然后重新命名一下这个WebService名,默认是Service1(这个是生成代码的namespace)
       应该会生成一个app.config文件,   <bindings>配置节里有个customerBindings的配置节可以删去。   <endpoint>也有重复的,把那个WeatherWebServiceSoap12的节点删去。3. 看下面的代码就可以用了。
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Text.RegularExpressions;namespace CallWebServices
    {
        public partial class Form1 : Form
        {
            private WeatherWebServices.WeatherWebServiceSoapClient weatherWebSvc = null;        public Form1()
            {
                InitializeComponent();
            }        private void Form1_Load(object sender, EventArgs e)
            {
                try
                {
                    weatherWebSvc = new CallWebServices.WeatherWebServices.WeatherWebServiceSoapClient();
                    weatherWebSvc.Open();                string[] cities = weatherWebSvc.getSupportCity("");                DataTable weatherData = new DataTable();
                    weatherData.Columns.Add("province");
                    weatherData.Columns.Add("city");
                    weatherData.Columns.Add("city_code");
                    weatherData.Columns.Add("city_image");
                    weatherData.Columns.Add("last_update_time");
                    weatherData.Columns.Add("temperature");
                    weatherData.Columns.Add("summary");
                    weatherData.Columns.Add("wind_direction");
                    weatherData.Columns.Add("wind_power");
                    weatherData.TableName = "WeatherData";                Regex regex = new Regex(@"(\d+)");                foreach (string city in cities)
                    {
                        string cityCode = regex.Match(city).Value;
                        string[] weatherDataArr = weatherWebSvc.getWeatherbyCityName(cityCode);
                        DataRow row = weatherData.NewRow();
                        for (int i = 0; i < weatherData.Columns.Count; i++)
                            row[i] = weatherDataArr[i];
                        weatherData.Rows.Add(row);
     
                        //城市太多了,全查受不了,所以随便查几个就Stop了。
                        if (weatherData.Rows.Count > 5)
                            break;
                    }                //绑定查询结果,显示
                    this.dataGridView1.DataSource = weatherData;
                    //利用DataTable保存成Xml
                    weatherData.WriteXml(@"D:\temp\weather.xml");                weatherWebSvc.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    try
                    {
                        weatherWebSvc.Close();
                    }
                    catch
                    { }
                }
                
            }
        }
    }
    生成Xml格式:
    <?xml version="1.0" standalone="yes"?>
    <DocumentElement>
      <WeatherData>
        <province>直辖市</province>
        <city>北京</city>
        <city_code>54511</city_code>
        <city_image>54511.jpg</city_image>
        <last_update_time>2010-10-15 14:04:50</last_update_time>
        <temperature>10℃/22℃</temperature>
        <summary>10月15日 晴转多云</summary>
        <wind_direction>无持续风向微风</wind_direction>
        <wind_power>0.gif</wind_power>
      </WeatherData>
      <WeatherData>
        <province>直辖市</province>
        <city>上海</city>
        <city_code>58367</city_code>
        <city_image>58367.jpg</city_image>
        <last_update_time>2010-10-15 14:18:38</last_update_time>
        <temperature>15℃/24℃</temperature>
        <summary>10月15日 多云转晴</summary>
        <wind_direction>东北风3-4级转东南风3-4级</wind_direction>
        <wind_power>1.gif</wind_power>
      </WeatherData>
      <WeatherData>
        <province>直辖市</province>
        <city>天津</city>
        <city_code>54517</city_code>
        <city_image>54517.jpg</city_image>
        <last_update_time>2010-10-15 14:04:08</last_update_time>
        <temperature>11℃/22℃</temperature>
        <summary>10月15日 晴转多云</summary>
        <wind_direction>西南风3-4级转东北风3-4级</wind_direction>
        <wind_power>0.gif</wind_power>
      </WeatherData>
      <WeatherData>
        <province>直辖市</province>
        <city>重庆</city>
        <city_code>57516</city_code>
        <city_image>57516.jpg</city_image>
        <last_update_time>2010-10-15 14:01:43</last_update_time>
        <temperature>17℃/23℃</temperature>
        <summary>10月15日 阴转多云</summary>
        <wind_direction>无持续风向微风</wind_direction>
        <wind_power>2.gif</wind_power>
      </WeatherData>
      <WeatherData>
        <province>特别行政区</province>
        <city>香港</city>
        <city_code>45005</city_code>
        <city_image>45005.jpg</city_image>
        <last_update_time>2010-10-15 14:00:14</last_update_time>
        <temperature>24℃/27℃</temperature>
        <summary>10月15日 阵雨转多云</summary>
        <wind_direction>东北风4-5级</wind_direction>
        <wind_power>3.gif</wind_power>
      </WeatherData>
      <WeatherData>
        <province>特别行政区</province>
        <city>澳门</city>
        <city_code>45011</city_code>
        <city_image>45011.jpg</city_image>
        <last_update_time>2010-10-15 14:02:48</last_update_time>
        <temperature>23℃/27℃</temperature>
        <summary>10月15日 阵雨转多云</summary>
        <wind_direction>东北风4-5级</wind_direction>
        <wind_power>3.gif</wind_power>
      </WeatherData>
    </DocumentElement>
      

  5.   

    先谢谢,有些地方还没看懂,先给分了,写的太好 我学的太浅薄了 有点看不懂。
    System.Threading.Timer tUpdatefile = new System.Threading.Timer(new TimerCallback(test), null, 0, 3*60*60 * 1000);  能帮我拆分解释下么。
      

  6.   

    <book ID="45"><Author>4545</Author><Title>45464</Title></book>