The latest release of .NET has added several interesting new things. One of those is support for Syndication. The System.ServiceModel.Web assembly has several classes that you can use to expose an ATOM or RSS feed. There”s already a cool article on how to achieve this which has been published on MSDN, so I”m not going to bother you with the details (you can check the code online, but don”t download it because it”s not updated; instead, browse the online version). The only thing I”d like to add to what is presented on the article is how to make Firefox interpret the RSS generated as RSS (instead of interpreting it like XML).
The problem with FF is that it will only consider the XML to be RSS feed if it has all the mandatory elements. If you”re like me, you”re probably going to go through all the public properties of the SyndicationFeed object and you”ll set those that make sense. Unfortunately, there really isn”t any called link (though there”s a Links collection property) so I didn”t set up that element from my code (and <link> is one of the mandatory channel elements! – ok, my fault. Should have read the specs to see which items were mandatory…). And that”s why I lost almost one hour trying to understand why FF wasn”t applying its default XSLT stylesheet to my RSS content. I could see the XML, but then I got that awful message that said that there wasn”t any stylesheet file applied to my XML document. In fact, it looks like I wasn”t the only one that forgot to define the RSS link element: if you try to run the code presented on the sample, you”ll see something like this:
The only thing you need to fix the code is to add a link element to the feed, which can be done with code that looks like this:
feed.Links.Add(SyndicationLink.CreateAlternateLink(new Uri(“put a valid URI here”)));
where feed is a reference to a SyndicationFeed object.
Now, if I only could make it add global namespaces,then I”d really be a happy man! (ok,You can add namespaces to the <channel> element, but what I want is to add those declarations on the top <rss> element)