Introduction
In My previous article “Creating Web feeds with WCF†, I have explained about building a web feed with WCF. This post explains how to build a simple WCF service that exposes the feed data using both RSS and Atom.
We are using both formats to emphasize the separation in WCF between the data [SyndicationFeed] and the formatting [SyndicationFeedFormatter].We can write the methods to return the Atom10FeedFormatter or the Rss20FeedFormatter.
The service contract is:
1: [ServiceContract]
2: public interface IEventLogFeed
3: {
4: [OperationContract]
5: [WebGet(UriTemplate = "/{log}/feed.rss" ) ]
6: Rss20FeedFormatter GetRSSData(string log);
7:
8: [OperationContract]
9: [WebGet(UriTemplate = "/{log}/feed.atom")]
10: Atom10FeedFormatter GetRSSData(string log);
11: }
1: public class EventLogFeed : IEventLogFeed
2: {
3:
4: public Rss20FeedFormatter GetRssData(string log)
5: {
6: SyndicationFeed feed = GetFeed(log);
7: Rss20FeedFormatter formatter = new Rss20FeedFormatter(feed);
8: return formatter;
9: }
10:
11: public Atom10FeedFormatter GetRssData(string log)
12: {
13: SyndicationFeed feed = GetFeed(log);
14: Atom10FeedFormatter formatter = new Atom10FeedFormatter(feed);
15: return formatter;
16: }
Now you can host this service in any of the WCF Hosting options.
The base URI of this service will look like /feed.atom">/feed.atom">http://localhost/EventLogFeed/<Application>/feed.atom or /feed.rss">/feed.rss">http://localhost/EventLogFeed/<Application>/feed.rss
The content in this article is based on Jon Flander’s article in visual systems journal.
Once we decided which formatted data that we want to use for the feed URI then rest of the things are taken care by WCF infrastructure.