题目如上,我是个新手,代码实现上有些困难,总是会出现错误,希望
1,用代码实现获取天气信息,能告诉下思路(希望不是自己创建Webservice和网上的同步)
2,给出部分代码参考,代码格式多点更好!
3,如何在VS2008上生成XML格式,告诉下具体操作.
4,能够加Timer控件,3小时刷新下数据(方便的话就给)
在线等答案,谢谢帮助!
1,用代码实现获取天气信息,能告诉下思路(希望不是自己创建Webservice和网上的同步)
2,给出部分代码参考,代码格式多点更好!
3,如何在VS2008上生成XML格式,告诉下具体操作.
4,能够加Timer控件,3小时刷新下数据(方便的话就给)
在线等答案,谢谢帮助!
解决方案 »
- 新手求教 如何实现双击listview的items项打开对应的窗体
- 一道令人遗憾的考研复试题,拿出来和大家交流交流
- c#编程 ASp.NET 3D编程 DirectX SDK sliverlight 问题
- 【紧急求助】一个系统的修改,涉及到VB版的老程序和C#的新程序通信,领导说用BIZ Service,请问BIZ Service是什么?
- .net发布问题
- 串行化问题,高手请进。。
- 请问微软是否有架构方面的培训或者提供技术支持,合作项目的服务?我公司在深圳,有无做过WINFORM多层系统的朋友提供点消息?
- 大家帮帮忙啊
- 求指教webBrowser如何跳转到新网页?
- 怎样实现datagrid和其页眉中的dropdownlist联动?
- MouseLeave事件有时候触发不了
- [散粉]两个hook的区别?如何在win7下做语音转化为文字的引用?
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)
{}
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>
System.Threading.Timer tUpdatefile = new System.Threading.Timer(new TimerCallback(test), null, 0, 3*60*60 * 1000); 能帮我拆分解释下么。