Share via


WCF RSS Sample

Mark is looking for some sample code for the recently released WCF RSS Toolkit. I've put the readme up here. I won't repeat the whole readme here but here's a peek at the programming model. There are several shortcuts for feeds from databases and feeds using existing data types so you should really check out the readme.

An example service:

using System;
using System.ServiceModel;
using System.Collections.Generic;
using Microsoft.ServiceModel.Samples.Syndication;
namespace Microsoft.ServiceModel.Samples.Syndication
{

    [ServiceContract]
    public class ItemListService
    {
       [OperationContract]
       ContentFeed<FeedItem> GetItemList()
       {

            //instantiate the feed
            ContentFeed<FeedItem> feed = new ContentFeed<FeedItem>();

            //populate the list of feed items
            feed.FeedItems = GenerateItemList();

            //set some feed-level properties
            feed.FeedAuthor = wcfuser@contoso.com;
            feed.FeedTitle = "WCF Item List!";

            ...

            //return the feed
            return feed;       

        }

        ItemList<FeedItem> GenerateItemList()

        {

            ItemList<FeedItem> list = new ItemList<FeedItem>();

            FeedItem item1 = new FeedItem();
            item1.ItemTitle = "This is item 1";

            ...

            list.Add(item1);

            ...

            return list;

        }

    }

}

To expose RSS, Atom and SOAP endpoints in code (see readme and samples in toolkit for config-based and hosting in IIS examples):

using System.ServiceModel;
using Microsoft.ServiceModel.Samples.Syndication;
namespace Microsoft.ServiceModel.Samples.Syndication
{

class Program
{

static void Main(string[] args)
{

ContentFeedHost host = new ContentFeedHost(
typeof(ItemListService),
new Uri("https://localhost:8077/ItemListService"));

//endpoints defined in code

// RSS endpoint will be listening at
//https://localhost:8077/ItemListService/rss
host.AddRssEndpoint(typeof(ItemListService), "rss");

// Atom endpoint will be listening at
//https://localhost:8077/ItemListService/atom
host.AddAtomEndpoint(typeof(ItemListService), "atom");

// WS-* SOAP endpoint will be listening at
//https://localhost:8077/ItemListService/soap
host.AddServiceEndpoint(typeof(ItemListService),
new WsHttpBinding(), "soap");

            host.Open();

            Console.WriteLine("Service started ...");
            Console.WriteLine("Press [Enter] to exit");
            Console.ReadLine();

            host.Close();

        }

    }

}

Enjoy!

Comments