Sebastien Lachance

Visual Studio 2008 - WCF Templates

When you want to create a new WCF project, you are presented with 4 different templates to use :

  • Sequential Workflow Service Library
  • Syndication Service Library
  • State Machine Workflow Service Library
  • WCF Service Library

Each one has it’s own particularities. It’s important to know which one to choose but you should know that the template only generate things you need to get started. You can always start from an empty WCF Service Library and build on top of it. Anyway, here is an explanation for each one.

Sequential Workflow Service Library

You basically create a sequential workflow project that made operations available by WCF. I have no experience with Workflow Foundation so I will not go further into details.

Syndication Service Library

This template is great. It present you a way to expose an RSS or Atom feed via a WCF Service contract. This is built-in stuff already present in the framework.

To expose a feed, you need an operation that return a  SyndicationFeedFormatter (in the System.ServiceModel.Syndication namespace). Then create a SyndicationFeed and add SyndicationItem to it. Finally, create a Atom10FeedFormatter or Rss20FeedFormatter and return it.

SyndicationFeed feed = new SyndicationFeed("Feed Title", "A WCF Syndication Feed", null);
List<SyndicationItem> items = new List<SyndicationItem>();

// Create a new Syndication Item.
SyndicationItem item = new SyndicationItem("An item", "Item content", null);
items.Add(item);
feed.Items = items;

// Return ATOM or RSS based on query string
// rss -> http://localhost:8731/Design_Time_Addresses/SyndicationServiceLibrary1/Feed1/
// atom -> http://localhost:8731/Design_Time_Addresses/SyndicationServiceLibrary1/Feed1/?format=atom
string query = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"];
SyndicationFeedFormatter formatter = null;
if (query == "atom")
{
formatter = new Atom10FeedFormatter(feed);
}
else
{
formatter = new Rss20FeedFormatter(feed);
}

return formatter;

 

State Machine Workflow Service Library

Another template that expose a Windows Workflow as a Service. This time the type of Workflow is a State Machine. A state machine workflow contrary to a sequential workflow is driven by external events. Transition between states are based on certain events until it reach the final state.

 

WCF Service Library

The most basic project to create a WCF service. You can use it to do everything you want with the most control.

Technorati Tags:

Comments