日期:2010-09-04  浏览次数:20524 次

  在前一篇文章(在ASP.NET Atlas中调用Web Service——创建Mashup调用远端Web Service(基础知识以及简单示例))中,我介绍了一些Atlas中对远程Web Service进行Mashup的基础知识,并给出了一个最基础的没有丝毫用处例子。今天再回到这个话题上,我将给出一个更复杂点的,但有一些用处的例子——Yahoo! Weather。

  废话到此为止,让我们先熟悉一下Yahoo! Weather服务:Yahoo!在其网站上提供了天气预报服务(http://weather.yahoo.com/),并且它也提供了Web Service的接口(http://developer.yahoo.com/weather/)

  从上面两个网页上面,我们可以知道Yahoo!提供的天气Service的URL为http://xml.weather.yahoo.com/forecastrss,该服务还有两个参数:

  p:要查询天气的地点代码(可以在http://weather.yahoo.com/查询到不同地方的这个代码)。

  u:返回结果中温度的单位,f代表华氏度,c代表摄氏度。

  看来这个Yahoo! Weather服务还挺简单的,让我们测试下好不好用。先到http://weather.yahoo.com/查出来上海的地点代码为CHXX0116。然后在浏览器中输入http://xml.weather.yahoo.com/forecastrss?p=CHXX0116&u=c,嗯,返回了如下的一段不是很复杂的XML:

Yahoo Weather Service XML Result
<?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 - Shanghai, CH</title>    <link>http://us.rd.yahoo.com/dailynews/rss/weather/Shanghai__CH/*http://xml.weather.yahoo.com/forecast/CHXX0116_c.html</link>
    <description>Yahoo! Weather for Shanghai, CH</description>
    <language>en-us</language>
    <lastBuildDate>Thu, 25 May 2006 11:00 am CST</lastBuildDate>
    <ttl>60</ttl>
    <yweather:location city="Shanghai" region="" country="CH" />
    <yweather:units temperature="C" distance="km" pressure="mb" speed="kph" />
    <yweather:wind chill="21" direction="260" speed="14" />
    <yweather:atmosphere humidity="78" visibility="299" pressure="0" rising="0" />
    <yweather:astronomy sunrise="4:52 am" sunset="6:50 pm" />
    <image>
      <title>Yahoo! Weather</title>
      <width>142</width>
      <height>18</height>
      <link>http://weather.yahoo.com/</link>
      <url>/UploadPic/2007-7/200777192443790.gif</url>
    </image>
    <item>
      <title>Conditions for Shanghai, CH at 11:00 am CST</title>
      <geo:lat>31.17</geo:lat>
      <geo:long>121.43</geo:long>      <link>http://us.rd.yahoo.com/dailynews/rss/weather/Shanghai__CH/*http://xml.weather.yahoo.com/forecast/CHXX0116_c.html</link>
      <pubDate>Thu, 25 May 2006 11:00 am CST</pubDate>
      <yweather:condition text="Fog" code="20" temp="21" date="Thu, 25 May 2006 11:00 am CST" />
      <description>
        <![CDATA[
          <img src="/UploadPic/2007-7/200777192443883.gif" /><br />
           <b>Current Conditions:</b><br />
           Fog, 21 C<BR /><BR />
           <b>Forecast:</b><BR />
            Thu - Scattered Thunderstorms. High: 25 Low: 20<br />
            Fri - AM Shower