A feed on the web is data format where users can read content from different web sites by subscribing using client applications. Building and exposing a web feed is not a new idea but in this post we are going to use WCF to build the feeds.WCF allows you to create feeds for both Atom1 and RSS2 standards.
Building a Feed with WCF
The following are two important features in WCF allows us to build the feeds.
Types in the Syndication namespace represents the structure of the feed in the memory and WCF can serialize those feeds into XML formats for feed readers to understand. SyndicationFeed type in this namespace supports two formats – RSS 2.0 and Atom 1.0.
The object model implemented by SyndicationFeed and types in the System.ServiceModel.Syndication namespace allows you to take the data from your feed and put into the WCF feed object model. The WCF object model then take care of serializing those objects into the appropriate XML for your feed.
You can create a WCF Syndication service in VS 2008 as follows
The following code creates a top-level SyndicationFeed object from EventLog data.
We have created a basic feed and now we look at the data inside the feed.
The most used property of SyndicationFeed is Items. Each <entry /> in the case of Atom or <item /> in the case of RSS represents the item in the feed.
Another important property is Content which represents the contents of an item can be text, XML or a URI. You can add the content to above created feed as follows
SyndicationFeed is not format-specific and you need to format the data inside the feed using SyndicationFeedFormatter.You can format feed either in RSS or Atom using the same SyndicationFeed object.
WriteTo method on SyndicationFeedFormatter is useful for writing feeds.
This article explained the basics for creating the webfeed with WCF and content is based on Jon Flander’s article on Visual Systems Journal.
In the next article I will discuss about exposing a Feed on Live URI.
|Share this post :|