天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

利用YAHOO公開API做天氣預(yù)報Web服務(wù)

系列文章導(dǎo)航:

創(chuàng)建一個示例和WebMethod特性解析

WebService特性和數(shù)組類型解析

類和結(jié)構(gòu)體解析

利用YAHOO公開API做天氣預(yù)報Web服務(wù)

Webservice 的設(shè)計和模式

Remoting和Webservice的區(qū)別


學(xué)了一段時間的Web服務(wù),今天做了一個Web服務(wù),利用YAHOO的公開天氣API做自己的Web服務(wù),主要是想練練手。現(xiàn)在把過程和心得分享給大家。

求教:這個Web服務(wù)還有個不完善的地方,Web服務(wù)的CityNameToCityNum方法,這個最重要,他是把省會和直轄市的名字轉(zhuǎn)換為編號,因為YAHOO傳的參數(shù)不是城市名字的區(qū)號,全是自己的,而我又想不到更好的獲得YAHOO城市對應(yīng)的編號的方法,所以就創(chuàng)建了HASHTABLE存儲了中國的各個省會城市和直轄市,希望有高手提出更好的方法,能不用這樣,直接找YAHOO獲取編號,提取更多的城市,而不用把所有的中國所有的城市全寫在HASHTABLE里。


Web服務(wù)地址:http://www.h2bbs.com/Weather/Weather.asmx

 

原理:

 在Yahoo的Developer NETwork

http://developer.yahoo.com/weather/

詳細(xì)地介紹了Yahoo天氣預(yù)報的API調(diào)用方法,這里用C#來實現(xiàn),本文主要是利用它的API做Web服務(wù),其它的應(yīng)用由網(wǎng)友們自由發(fā)揮

首先了解Yahoo Weather Api的RSS Response格式(這是下午我查我家銀川天氣時返回的RSS):

 

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
  
<channel>
    
<title>Yahoo! Weather - Yinchuan, CH</title>
    
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Yinchuan__CH/*[url]http://weather.yahoo.com/forecast/CHXX0259_f.html[/url]</link>
    <description>Yahoo! Weather for Yinchuan, CH</description>
    
<language>en-us</language>
    
<lastBuildDate>Tue, 14 Oct 2008 11:00 am CST</lastBuildDate>
    
<ttl>60</ttl>
    
<yweather:location city="Yinchuan" region=""  country="CH"/>
    
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
    
<yweather:wind chill="56"  direction="360"  speed="4" />
    
<yweather:atmosphere humidity="56"  visibility="999"  pressure=""  rising="0" />
    
<yweather:astronomy sunrise="7:03 am"  sunset="6:19 pm"/>
    
<image>
      
<title>Yahoo! Weather</title>
      
<width>142</width>
      
<height>18</height>
      
<link>http://weather.yahoo.com</link>
      <url>http://l.yimg.com/us.yimg.com/i/us/nws/th/main_142b.gif</url>
    </image>
    
<item>
      
<title>Conditions for Yinchuan, CH at 11:00 am CST</title>
      
<geo:lat>38.48</geo:lat>
      
<geo:long>106.22</geo:long>
      
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Yinchuan__CH/*[url]http://weather.yahoo.com/forecast/CHXX0259_f.html[/url]</link>
      <pubDate>Tue, 14 Oct 2008 11:00 am CST</pubDate>
      
<yweather:condition  text="Mostly Cloudy"  code="28"  temp="56"  date=
"
Tue, 14 Oct 2008 11:00 am CST" />
      
<description>
        
<![CDATA[
<img src="
[img]http://l.yimg.com/us.yimg.com/i/us/we/52/28.gif[/img]"/><br />
<b>Current Conditions:</b><br />
Mostly Cloudy, 
56 F<BR />
<BR /><b>Forecast:</b><BR />
Tue 
- Mostly Cloudy. High: 68 Low: 47<br />
Wed 
- Partly Cloudy. High: 70 Low: 44<br />
<br />
<a href="Full'>http://us.rd.yahoo.com/dailynews/rss/weather/Yinchuan__CH/*http://weather.yahoo.com/forecast/CHXX0259_f.html">Full Forecast at Yahoo! Weather</a><BR/>
(provided by The Weather Channel)
<br/>
]]
>
      
</description>
      
<yweather:forecast day="Tue" date="14 Oct 2008" low="47" high="68" text
=
"Mostly Cloudy" code="28" />
      
<yweather:forecast day="Wed" date="15 Oct 2008" low="44" high="70" text
=
"Partly Cloudy" code="30" />
      
<guid isPermaLink="false">CHXX0259_2008_10_14_11_00_CST</guid>
    
</item>
  
</channel>
</rss>
<!-- api5.weather.sp1.yahoo.com compressed/chunked Mon Oct 13 22:30:39 PDT
2008
 -->

系列文章導(dǎo)航:

創(chuàng)建一個示例和WebMethod特性解析

WebService特性和數(shù)組類型解析

類和結(jié)構(gòu)體解析

利用YAHOO公開API做天氣預(yù)報Web服務(wù)

Webservice 的設(shè)計和模式

Remoting和Webservice的區(qū)別


 

 

其中最重要的是后面的幾行,查詢當(dāng)天和第二天的天氣情況,我們要獲取的天氣信息就在里面,代碼如下:

 

     <yweather:forecast day="Tue" date="14 Oct 2008" low="47" high="68" text
=
"Mostly Cloudy" code="28" />
      
<yweather:forecast day="Wed" date="15 Oct 2008" low="44" high="70" text
=
"Partly Cloudy" code="30" />

系列文章導(dǎo)航:

創(chuàng)建一個示例和WebMethod特性解析

WebService特性和數(shù)組類型解析

類和結(jié)構(gòu)體解析

利用YAHOO公開API做天氣預(yù)報Web服務(wù)

Webservice 的設(shè)計和模式

Remoting和Webservice的區(qū)別


 

Web服務(wù)的代碼中有一個Web公開方法,四個私有方法:

(1)GetWeather方法是公共方法,提供Web調(diào)用。

(2)FToC方法,他主要是把RSS返回的華氏溫度轉(zhuǎn)換成攝氏溫度,其實這一步可以不用的,當(dāng)初沒發(fā)現(xiàn),URL中加點參數(shù)就返回的是攝氏溫度。

(3)EweekToCweek方法,他主要是把英文的星期縮寫變成中文。

(4)EmonthToCmonth方法,它主要是把英文的月份縮寫變成中文,并重新排序。

(5)CityNameToCityNum方法,這個最重要,他是把省會和直轄市的名字轉(zhuǎn)換為編號,因為YAHOO傳的參數(shù)不是城市名字的區(qū)號,全是自己的,而我又想不到更好的獲得YAHOO城市對應(yīng)的編號的方法,所以就只能支持這么幾個城市了,希望有高手提出更好的方法,能不用這樣,直接找YAHOO獲取編號。

 

系列文章導(dǎo)航:

創(chuàng)建一個示例和WebMethod特性解析

WebService特性和數(shù)組類型解析

類和結(jié)構(gòu)體解析

利用YAHOO公開API做天氣預(yù)報Web服務(wù)

Webservice 的設(shè)計和模式

Remoting和Webservice的區(qū)別


 

查詢個中國隨便的省會,效果如下

 <?xml version="1.0" encoding="utf-8" ?> 

- <DataSet xmlns="http://www.h2bbs.com/WebService/Weather.asmx">


- <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">


- <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:
UseCurrentLocale
="true">


- <xs:complexType>


- <xs:choice minOccurs="0" maxOccurs="unbounded">


- <xs:element name="Weather">


- <xs:complexType>


- <xs:sequence>


  
<xs:element name="Date" type="xs:string" minOccurs="0" /> 

  
<xs:element name="Week" type="xs:string" minOccurs="0" /> 

  
<xs:element name="Weather" type="xs:string" minOccurs="0" /> 

  
<xs:element name="Tlow" type="xs:string" minOccurs="0" /> 

  
<xs:element name="Thigh" type="xs:string" minOccurs="0" /> 
  
</xs:sequence>
  
</xs:complexType>
  
</xs:element>
  
</xs:choice>
  
</xs:complexType>
  
</xs:element>
  
</xs:schema>

- <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">


- <NewDataSet xmlns="">


- <Weather diffgr:id="Weather1" msdata:rowOrder="0" diffgr:hasChanges="inserted">


  
<Date>2008年10月14日</Date> 

  
<Week>星期二(Tue)</Week> 

  
<Weather>Clear</Weather> 

  
<Tlow>16.1</Tlow> 

  
<Thigh>26.7</Thigh> 
  
</Weather>

- <Weather diffgr:id="Weather2" msdata:rowOrder="1" diffgr:hasChanges=
"inserted">


  
<Date>2008年10月15日</Date> 

  
<Week>星期三(Wed)</Week> 

  
<Weather>Sunny</Weather> 

  
<Tlow>16.7</Tlow> 

  
<Thigh>28.3</Thigh> 
  
</Weather>
  
</NewDataSet>
  
</diffgr:diffgram>
  
</DataSet>

NET技術(shù)利用YAHOO公開API做天氣預(yù)報Web服務(wù),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 精品久久免费观看 | 曰产无码久久久久久精品 | 黑人巨茎大战白人女40CMO | 久久精品免费看网站 | 2018高清国产一区二区三区 | 97在线视频免费播放 | 日本亚欧热亚洲乱色视频 | 六级黄色片 | 国产成人免费高清视频 | 高h乱np甄宓| 好湿好滑好硬好爽好深视频 | babesvideos欧美最新| 国产精品路线1路线2路线 | 欧美一区二区在线观看 | 好好的曰com久久 | 高h 纯肉文 | 暖暖视频大全免费观看 | 午夜亚洲动漫精品AV网站 | 嘟嘟嘟WWW免费高清在线中文 | 亚洲精品国产乱码AV在线观看 | 婷婷激情综合色五月久久竹菊影视 | 久久精品一本到东京热 | 亚洲一区二区三区免费看 | 亚洲国产系列一区二区三区 | 亚洲三级视频 | 战狼4在线观看完免费完整版 | 国产中文字幕免费观看 | 两个人看的www免费高清直播 | 国产WW久久久久久久久久 | 国产成人免费手机在线观看视频 | 99热久久这里只有精品 | 无限资源好看片2019免费观看 | 91九色精品国产免费 | 亚洲精品免费网站 | 无人区乱码1区2区3区网站 | 久久国产欧美日韩精品免费 | 男人就爱吃这套下载 | 精品一二三区久久AAA片 | 四虎视频最新视频在线观看 | 泡妞高手在都市完整版视频免费 | 污污内射在线观看一区二区少妇 |