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

利用YAHOO公開API做天氣預報Web服務

系列文章導航:

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

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

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

利用YAHOO公開API做天氣預報Web服務

Webservice 的設計和模式

Remoting和Webservice的區(qū)別


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

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


Web服務地址:http://www.h2bbs.com/Weather/Weather.asmx

 

原理:

 在Yahoo的Developer NETwork

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

詳細地介紹了Yahoo天氣預報的API調(diào)用方法,這里用C#來實現(xiàn),本文主要是利用它的API做Web服務,其它的應用由網(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
 -->

系列文章導航:

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

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

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

利用YAHOO公開API做天氣預報Web服務

Webservice 的設計和模式

Remoting和Webservice的區(qū)別


 

 

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

 

     <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" />

系列文章導航:

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

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

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

利用YAHOO公開API做天氣預報Web服務

Webservice 的設計和模式

Remoting和Webservice的區(qū)別


 

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

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

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

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

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

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

 

系列文章導航:

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

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

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

利用YAHOO公開API做天氣預報Web服務

Webservice 的設計和模式

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做天氣預報Web服務,轉(zhuǎn)載需保留來源!

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

主站蜘蛛池模板: 久久免费看少妇高潮A片JA | 欧美97色伦影院在线观看 | 1区2区3区4区产品不卡码网站 | 乱码午夜-极品国产内射 | YELLOW免费观看2019 | 中文字幕高清在线中文字幕 | 自拍视频亚洲综合在线精品 | 99在线观看视频免费 | 国产精华av午夜在线观看 | 国产AV电影区二区三区曰曰骚网 | 永久久久免费人妻精品 | GAY2022空少被体育生暴菊 | 无人影院在线播放 | 久久亚洲午夜牛牛影视 | yellow在线观看免费高清的日本 | 老汉老太bbbbbxxxxx | 老师洗澡让我吃她胸的视频 | 性夜影院午夜看片 | 亚洲AV永久无码精品老司机蜜桃 | 黄小说免费看 | 中文在线中文资源 | 成人在线免费视频 | 欧美男同gay粗大又长 | 在线视频免费国产成人 | 色欲天天婬色婬香影院 | SM高H黄暴NP辣H调教性奴 | 99久久免费只有精品 | 久久久精品免费免费直播 | 久久久欧美国产精品人妻噜噜 | 女人被躁到高潮嗷嗷叫69 | 乳液全集电影在线观看 | 洲精品无码高潮喷水A片 | 亚洲中文字幕永久在线 | 欧洲另类一二三四区 | 考好老师让你做一次H | 精品欧美一区二区三区四区 | 色戒床震视频片段 | 久久久精品免费视频 | 亚洲热在线视频 | 伊人免费在线 | 日韩精品亚洲专区在线电影不卡 |