C# 天气预报
问题描述:
使用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# 天气预报的更多相关文章
- WEB前端工程师(实践)制作天气预报难度:简单
需要准备:jQuery Bootstrap 天气预报API(本文中使用API可能会失效请灵活运用) CSS样式可以你自己去写这里只提出jQuery 请求数据和解析JSON数据 { "resu ...
- 天气预报API开发
天气预报API开发 一. 寻觅篇 最近想要跟着视频练习一下利用API开发一个天气预报系统,就在网上找了一下可以用的API,结果好多都已经失效了... 1. 百度车联网天气预报 ...
- arcgis for flex全国地图天气预报的具体实现过程解析
系统架构是B/S,开发语言是flex,开发工具是myeclise或者flashbuild,通过调用百度提供的在线天气预报web api接口的方式来实现. 采用地图是ArcGIS全国地图,开发接口为ar ...
- 【代码笔记】iOS-获得徐家汇的天气预报
一,代码. //获得徐家汇的天气预报 -(void)getWeatherInfo{ NSError *error; NSURLRequest *request = [NSURLRequest requ ...
- webservice通信调用天气预报接口实例
转载:http://www.cnblogs.com/warrior4236/p/5668449.html 一:环境搭建 1:新建一个java project工程weatherInf 2:引入相应的ja ...
- 开源免费天气预报接口API以及全国所有地区代码!!(国家气象局提供) 【转】
国家气象局提供的天气预报接口 接口地址: http://www.weather.com.cn/data/sk/101010100.html http://www.weather.com.cn/data ...
- 常用Web Service汇总(天气预报、时刻表等)
现成的Web Service中有很多很好用的,比如天气预报,IP地址搜索,火车时刻表等等.本文汇总的一些常用Web Service,希望对大家有所帮助. AD: ================= ...
- 开源免费的天气预报接口API以及全国所有地区代码(国家气象局提供)
天气预报一直是各大网站的一个基本功能,最近小编也想在网站上弄一个,得瑟一下,在网络搜索了很久,终于找到了开源免费的天气预报接口API以及全国所有地区代码(国家气象局提供),具体如下: 国家气象局提供的 ...
- 天气预报API(三):免费接口测试(“旧编码”)
说明 我以参考文章为引子,自己测试并扩展,努力寻找更多的气象API... 本文所有测试均以青岛为例. 本文所列接口城市代码(cityid)参数都使用的 "旧编码": 全国城市代码列 ...
- 天气预报API(四):全国城市代码列表(“新编码”)
说明 天气预报API系列文章涉及到的天气网站10个左右,只发现了中国气象频道和腾讯天气城市代码参数特别: 暂且称 中国气象频道.腾讯天气使用的城市代码为 "新编码" 注:中国气象频 ...
随机推荐
- 大体了解Lua的语法
Lua 的语法比较简单,学习起来也比较省力,但功能却并不弱. 在Lua中,一切都是变量,除了关键字.请记住这句话. I. 首先是注释 写一个程序,总是少不了注释的. 在Lua中,你可以使用单行注释和多 ...
- android开源代码
Android开源项目--分类汇总 转自:https://github.com/Trinea/android-open-project Android开源项目第一篇——个性化控件(View)篇 包括L ...
- ASP.NET中前台调用后台的方法
学习文章:http://www.cnblogs.com/kingteach/archive/2010/11/12/1875633.html 练习代码: 前台: <html xmlns=" ...
- Java 第二天
1.不带访问修饰符号的类成员变量默认是friendly(可以同一个包中访问) 2.protected的类成员可以在同一个包及其子类中访问 3.方法中可以定义内部类(如下面的代码),该类只能访问方法中的 ...
- 查看binlog文件的2种方式
1.使用show binlog events a.获取binlog文件列表 mysql> show binary logs; +------------------+-----------+ | ...
- jquery.unobtrusive-ajax.js源码阅读
/*! ** Unobtrusive Ajax support library for jQuery ** Copyright (C) Microsoft Corporation. All right ...
- python笔记第二天
上节内容回顾和补充 编程语言 高级 低级 Python种类 JavaPython cPython ***** pypy 字节码 和 机器码 Python程序: 1. 终端: C:\python35\p ...
- build a git repo and clone
First machine: git init --bare gitrepo.git Second machine: git clone user@server:~/gitrepo.git cd gi ...
- Microsoft Power BI Designer
1/25/2015年1月25发布的预览版本,可以通过以下地址下载,注意有x64 和x32 版本区别(和上次PowerMap一样,一般也推荐的使用x64版本) http://www.microsoft. ...
- MVC4.0网站发布和部署到IIS7.0上的方法【转:http://www.th7.cn/Program/net/201403/183756.shtml】
最近在研究MVC4,使用vs2010,开发的站点在发布和部署到iis7上的过程中遇到了很多问题,现在将解决的过程记录下来,以便日后参考,整个过程主要以截图形式呈现 vs2010的安装和mvc4的安装不 ...