开始的设置详见:
应该还看了个帖子,暂时找不到了
网址现在改成http://ws.webxml.com.cn/WebServices/WeatherWS.asmx,替换下就好了。
需要注意的内容:这个网站每天早上九点更新当日天气,所以如果9点钟之前运行应显示明天和后天的天气;
网站会不定期维护,且有时会拒绝访问需要考虑未连接情况
cn.com.webxml.www.WeatherWS w = new cn.com.webxml.www.WeatherWS();
//把webservice当做一个类来操作
string[] s = new string[30];//声明string数组存放返回结果
string city = "潍坊";//获得文本框录入的查询城市
s = w.getWeather(city, "");
try
{
//以文本框内容为变量实现方法getWeatherbyCityName ,获得所在地方的天气
TimeSpan workStart = DateTime.Parse("9:00").TimeOfDay;
TimeSpan nowTime = DateTime.Now.TimeOfDay;
if (nowTime < workStart)//获取天气的网站每天上午9点更新当日天气,增加条件语句,9点之前打开读取明天及后天天气。
{
pictureBox2.Image = Image.FromFile(@"D:\工作\大屏\生日\HAPPYBIRTHDAY\weather\" + s[15] + "");//今日天气、温度
label13.Text = s[13];
label15.Text = s[12];
pictureBox4.Image = Image.FromFile(@"D:\工作\大屏\生日\HAPPYBIRTHDAY\weather\" + s[20] + "");//明日天气、温度
label14.Text = s[18];
label16.Text = s[17];
}
else
{
pictureBox2.Image = Image.FromFile(@"D:\工作\大屏\生日\HAPPYBIRTHDAY\weather\" + s[10] + "");//今日天气、温度
label13.Text = s[8];
label15.Text = s[7];
pictureBox4.Image = Image.FromFile(@"D:\工作\大屏\生日\HAPPYBIRTHDAY\weather\" + s[15] + "");//明日天气、温度
label14.Text = s[13];
label16.Text = s[12];
}
}
catch
{
MessageBox.Show("天气网站正在维护,请暂时使用,2小时后打开检查,若仍有问题请联系制作人员进行调试", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.TopMost = true;//将该窗体置顶
}