Well, writing this up took longer than I thought :-) I guess I've been really busy. So, to implement the WCF-based RSS and Atom endpoints for dasBlog, I used the new System.ServiceModel.Syndication namespace from the Orcas CTP, except that the engineers created a separate DLL (Microsoft.ServiceModel.Synidcation.dll) that contains all the classes and can be used on top of NetFX 3.0 (i.e. no Orcas dependencies). Complete source for the whole thing is available upon request :-) The main implementation file is WCFSyndicationServiceImplementation.cs, and looks like this. using System.ServiceModel.Activation; using System.ServiceModel.Syndication; ... [AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)] public class WCFSyndicationServiceImplementation : SyndicationServiceBase, IWCFSyndicationService { [HttpTransferContract(Method = "GET", Path = "")] public SyndicationFeed GetFeed() { int maxDays = siteConfig.RssDayCount; int maxEntries = siteConfig.RssMainEntryCount; return GetFeedWithCounts(maxDays, maxEntries); } Note that we're in AspNet compat mode, and that I inherit my implementation class from a new ServiceBase called SyndicationServiceBase. The contract (IWCFSyndicationService) has just the GetFeed method, so I elide it here. Also worth noting is the HttpTransferContract attribute - this is new and allows you to indicate that this method is dispatched from an HTTP GET (as opposed to the default POST). Finally, note the SyndicationFeed return type - this is a type that is automatically serialized either as Atom or RSS, depending on an endpoint behavior that I will set in config later. The following snippet is the core of the implementation, and creates a new SyndicationFeed and all the items underneath it. It has alot of dasBlog-isms (takes advantage of many helper classes in dasBlog) so it may be a bit hard to follow, but you'll get the gist of the OM... private SyndicationFeed GetFeedCore(string category, int maxDayCount, int maxEntryCount) { //... SyndicationFeed feed = HttpContext.Current.Cache[CacheKey] as SyndicationFeed; if (feed == null) //we'll have to build it... { feed = new SyndicationFeed (); if (siteConfig.RssLanguage != null && siteConfig.RssLanguage.Length > 0) { //feed.Lang = siteConfig.RssLanguage; feed.Language = siteConfig.RssLanguage; } if (category == null) { feed.Title = new TextSyndicationContent (siteConfig.Title); } feed.Description = new TextSyndicationContent(siteConfig.Subtitle);
Read More...