问题描述:

使用C#做一个简易的天气预报系统

问题解决:

主要使用类如下:

WeatherLoc:包含常用的调用中国气象局天气情况接口

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WeatherReport.ServiceReference1; namespace WeatherReport
{
class WeatherLoc
{
//调用天气接口的类

private static WeatherWebServiceSoapClient ws= new WeatherWebServiceSoapClient("WeatherWebServiceSoap"

);

        public WeatherLoc()
{
}
     //查看天气接口支持的省份
public String[] GetSupportProvince()
{
String[] supportProv = ws.getSupportProvince();
return supportProv;
}
    //查看天气情况支持的城市
public String[] GetSupportCity(String province)
{
return ws.getSupportCity(province);
}
     //查看指定城市的天气信息
public WeatherInfo GetWeatherInfo(String city)
{
String[] allInfo = ws.getWeatherbyCityName(city);
WeatherInfo weather = new WeatherInfo();
weather.Province = allInfo[];
weather.CityName = allInfo[];
weather.LastUpdateTime = allInfo[];
weather.Temperature = allInfo[];
weather.WeatherLive = allInfo[];
weather.LivingIndex = allInfo[];
weather.CityInfo = allInfo[]; FutureInfo[] future = new FutureInfo[]; //今天天气信息
future[].temp = allInfo[];
future[].overView = allInfo[];
future[].windDirection = allInfo[];
future[].tendencyBeg = allInfo[];
future[].tendencyEnd = allInfo[]; //明天的天气信息
future[].temp = allInfo[];
future[].overView = allInfo[];
future[].windDirection = allInfo[];
future[].tendencyBeg = allInfo[];
future[].tendencyEnd = allInfo[]; //后天的天气信息
future[].temp = allInfo[];
future[].overView = allInfo[];
future[].windDirection = allInfo[];
future[].tendencyBeg = allInfo[];
future[].tendencyEnd = allInfo[]; weather.FutureInfo = future; return weather;
}
}
}

WeatherInfo类:包含查询天气情况信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace WeatherReport
{
//未来三天天气情况结构体,C#中结构体默认访问权限是private,C++结构体默认访问权限为public
struct FutureInfo
{
public String temp; //温度
public String overView; //概况
public String windDirection; //风向和风力
public String tendencyBeg; //趋势开始图片
public String tendencyEnd; //趋势结束图片
}; class WeatherInfo
{
private String province; //省份
private String cityName; //城市名称
private String lastUpdateTime; //最后更新时间
private String temperature; //温度
private FutureInfo[] info; //未来三天天气情况
private String weatherLive; //现在天气实况
private String livingIndex; //生活指数
private String cityInfo; //城市介绍 public WeatherInfo()
{
cityName = "";
lastUpdateTime = "";
temperature = "";
info = new FutureInfo[];
weatherLive = "";
livingIndex = "";
cityInfo = "";
} public String Province
{
get
{
return province;
}
set
{
province = value;
}
} public FutureInfo[] FutureInfo
{
get
{
return info;
}
set
{
info = value;
}
} public String CityName
{
get
{
return cityName;
} set
{
cityName = value;
}
} public String LastUpdateTime
{
get
{
return lastUpdateTime;
}
set
{
lastUpdateTime = value;
}
} public String Temperature
{
get
{
return temperature;
}
set
{
temperature = value;
}
} public String WeatherLive
{
get
{
return weatherLive;
}
set
{
weatherLive = value;
}
} public String LivingIndex
{
get
{
return livingIndex;
}
set
{
livingIndex = value;
}
} public String CityInfo
{
get
{
return cityInfo;
}
set
{
cityInfo = value;
}
}
}
}

具体使用中国气象局天气接口方法如下:

(1)添加服务引用

(2)包含服务器引用接口

(3)接口使用,参考WeatherLoc类中接口调用

执行效果:

C# 天气预报的更多相关文章

  1. WEB前端工程师(实践)制作天气预报难度:简单

    需要准备:jQuery Bootstrap 天气预报API(本文中使用API可能会失效请灵活运用) CSS样式可以你自己去写这里只提出jQuery 请求数据和解析JSON数据 { "resu ...

  2. 天气预报API开发

    天气预报API开发 一.        寻觅篇 最近想要跟着视频练习一下利用API开发一个天气预报系统,就在网上找了一下可以用的API,结果好多都已经失效了... 1.       百度车联网天气预报 ...

  3. arcgis for flex全国地图天气预报的具体实现过程解析

    系统架构是B/S,开发语言是flex,开发工具是myeclise或者flashbuild,通过调用百度提供的在线天气预报web api接口的方式来实现. 采用地图是ArcGIS全国地图,开发接口为ar ...

  4. 【代码笔记】iOS-获得徐家汇的天气预报

    一,代码. //获得徐家汇的天气预报 -(void)getWeatherInfo{ NSError *error; NSURLRequest *request = [NSURLRequest requ ...

  5. webservice通信调用天气预报接口实例

    转载:http://www.cnblogs.com/warrior4236/p/5668449.html 一:环境搭建 1:新建一个java project工程weatherInf 2:引入相应的ja ...

  6. 开源免费天气预报接口API以及全国所有地区代码!!(国家气象局提供) 【转】

    国家气象局提供的天气预报接口 接口地址: http://www.weather.com.cn/data/sk/101010100.html http://www.weather.com.cn/data ...

  7. 常用Web Service汇总(天气预报、时刻表等)

      现成的Web Service中有很多很好用的,比如天气预报,IP地址搜索,火车时刻表等等.本文汇总的一些常用Web Service,希望对大家有所帮助. AD: ================= ...

  8. 开源免费的天气预报接口API以及全国所有地区代码(国家气象局提供)

    天气预报一直是各大网站的一个基本功能,最近小编也想在网站上弄一个,得瑟一下,在网络搜索了很久,终于找到了开源免费的天气预报接口API以及全国所有地区代码(国家气象局提供),具体如下: 国家气象局提供的 ...

  9. 天气预报API(三):免费接口测试(“旧编码”)

    说明 我以参考文章为引子,自己测试并扩展,努力寻找更多的气象API... 本文所有测试均以青岛为例. 本文所列接口城市代码(cityid)参数都使用的 "旧编码": 全国城市代码列 ...

  10. 天气预报API(四):全国城市代码列表(“新编码”)

    说明 天气预报API系列文章涉及到的天气网站10个左右,只发现了中国气象频道和腾讯天气城市代码参数特别: 暂且称 中国气象频道.腾讯天气使用的城市代码为 "新编码" 注:中国气象频 ...

随机推荐

  1. C#中List〈string〉和string[]数组之间的相互转换

    1,从System.String[]转到List<System.String> System.String[] str={"str","string" ...

  2. [leetcode]_Path Sum I && II

    都是考查DFS.经典回溯算法,问题在于我对该类型的代码不熟悉,目前以参考别人的代码,然后加上自己的实现为主,通过类似的题目加强理解. 一.给定一棵二叉树,判断是否存在从root到leaf的路径和等于给 ...

  3. jQuery类级别插件--返回顶部,底部,去到任何部位

    先引入js:<script type="text/javascript" src="jquery.js" ></script><s ...

  4. centos+php+coreseek+sphinx+mysql之二sphinx配置篇

    先进入文件夹进行以下操作 cd /usr/local/coreseek/etc cp sphinx.conf.dist sphinx.conf source src1 { sql_host = 127 ...

  5. PHP-You don’t have permissions to access xxx on this server!

    问题如下图:   如果你是想要查看目录下的每一个文件,那么你需要修改一下httpd-conf配置文件,也就是apache的配置文件,以phpStudy2013为例,如下图打开: 然后找到如下部分,添加 ...

  6. 个人代码管理--svn

    通常开发中遇到自己电脑和公司电脑代码共享的问题.比如一些通用的库,图片等项目中基本通用. 一些项目库如google code, github内地访问又挺困难的,常常无法连接,或者慢死..还有就是必须开 ...

  7. DIV JS CSS 轻量级弹出层 兼容各浏览器

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. html中的框架

    1.总的代码 <frameset rows=20%,*> <frame src="top.html" /> <frameset cols=30%,*& ...

  9. SSM框架

    1.http://www.cnblogs.com/verlen11/p/5349747.html 2.Mybatis http://www.cnblogs.com/xdp-gacl/p/4261895 ...

  10. Java 第五天 Spring IOC 配置文件

    Spring xml结构定义文件: http://www.springframework.org/schema/beans/spring-beans.xsd 可用xsd列表: http://www.s ...