Chinaunix首页 | 论坛 | 博客
  • 博客访问: 199303
  • 博文数量: 163
  • 博客积分: 4010
  • 博客等级: 上校
  • 技术积分: 1720
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-08 11:41
文章分类

全部博文(163)

文章存档

2011年(1)

2009年(162)

我的朋友

分类: 系统运维

2009-06-17 15:28:06

 若是用户点击了RSS阅读器左侧导航栏中提要列表的某个提要,程序将调用Web Service中名为GetRssContent()的方法,用来根据提要的ID获取其内容,即一个ContentEntry数组。注意其中RSS.NET类库中RssFeed类的强大功能:
    ///
    /// 返回指定提要的内容。
    ///

    /// 提要的id
    /// 提要的内容
    [WebMethod]
    public ContentEntry[] GetRssContent(int id)
    {
        // 根据Id得到提要的URL。
        string rssUrl = getUrlByRssEntryId(id);
        if (string.IsNullOrEmpty(rssUrl))
        {
            return null;
        }
        // 根据URL创建一个RssFeed对象,并获取其基本信息。
        Rss.RssFeed feed = Rss.RssFeed.Read(rssUrl);
      
        // 提要中内容条目的列表。
        List contentEntries = new List();
      
        for (int index = 0; index < feed.Channels[0].Items.Count; ++index)
        {
            ContentEntry contentEntry = new ContentEntry(
                feed.Channels[0].Items[index].Title, // 标题
                feed.Channels[0].Items[index].Link.AbsoluteUri, // URL
                feed.Channels[0].Items[index].Description // 内容
            );
            contentEntries.Add(contentEntry);
        }
        return contentEntries.ToArray();
    }
    注意上述代码中粗体部分调用的getUrlByRssEntryId()辅助方法,用来根据ID取得提要的URL。该辅助方法的代码如下:
    ///
    /// 根据Id得到提要的URL。
    ///

    /// 提要的Id
    /// 提要的URL
    private string getUrlByRssEntryId(int id)
    {
        foreach (RssEntry entry in rssEntryList)
        {
            if (entry.Id == id)
            {
                return entry.Url;
            }
        }
        return null;
    }

    这样即完成了本RSS阅读器中用来维护数据的Web Service部分。

阅读(203) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~