Category Archives: Windows Workflow Foundation

Windows Workflow hosted as a WCF Service

I wrote an example about using two new features of Windows Worflow Foundation shipped in .NET 3.5: the workflow can be hosted and exposed as a Windows Communication Foundation Service, and the use of Receive Activity. I used Visual Studio 2008 Beta 2, as the IDE. This post it’s not a detailed step by step. It pretends to highlight some procedures and concepts.

The code can be downloaded from

It’s a minimalist example: a workflow instance is created, it waits for an external events, then it continues, writing a line to the console. Simpler, impossible.

The example contains a solution with:

– A console program that hosts and expose a sequential workflow.

– A client console program

– An interface, used by both programs

– A Sequential Workflow Library, with a Receive Activity, and a Code Activity.

This is the appearance of the final workflow design:

The workflow process an order, for a fictitious restaurant. First, I created a class library project, to define the common interface:

This interface define two methods: one to cook the order, and other to cancel it. The example only uses the cooked method (we’re optimistic), and nothing more. But in a more evolved example, we can include a create order method, and some decision branch in the workflow.

Note the using of System.ServiceModel, to mark with WCF attributes the interface and its methods.

In the Sequential Workflow Library, I initially dragged a Receive Activity:

It’s a new activity, that is in the revamped toolbox:

When you add the Receive Activity, it must be completed with a Service Operation Info (more about another important property in a following paragraph):

You can clicked on the ellipsis, to use a dialog:

Notably, you can create a contract, without write the interface. But, in this example, I choose to import the interface that I’d previously defined. Then, using the Import… button, you can select the interface, from the referenced assemblies (the workflow library project reference the class library project containing the interface definition) :

Pressing the OK button, you can select the method to use to invoke the Receive Activity:

The receive activity waits until an OrderCooked method invocation is received. This is a new way to manage the incoming events on a workflow. The interface contract will be exposed as a WCF service.

I added a code activity, after the receive activity, and wrote a simple code to write a message:

A host console program creates a Workflow Runtime, hosted under WCF:

Note the use of the new WorkflowServiceHost class, and the adding of a service endpoint to expose the order interface.

The client console program programmatically creates a WCF channel that use the interface, only to create a workflow instance, and make it advance, sending an OrderCooked method invocation:

You must notice that the program never create a workflow instance. Where is the instance created? Remember the Receive Activity: it has a property CanCreateInstance, and I set it to True:

In order to test the solution, I modify its properties, to launch the client and the host project at the same time:

And voila! Client outcome:

and Host outcome:

It’s not the ultimate workflow demo, but I hope that it will be useful to show these new features from .NET 3.5.

Thanks to Southworks and the Tamesis team, for the support to write this post.

Angel “Java” Lopez

Learning Windows Workflow Foundation

Recently, I collected some links and resources about Windows Workflow Foundation, the Microsoft workflow engine that is part of the upcoming .NET 3.0 platform. You can find more detailed information at

The engine can run on any NET 2.0 installation. You need to download and install it from the above link. Currently, WWF is a set of new namespaces (System.Workflow.*), and utilities (like Workflow Designer) that you can run and use from Visual Studio 2005.

The site dedicated to WWF from Microsoft, is:

If you want to study about this engine, I can suggest some links, from my developer link bag:

Windows Workflow Reference

Windows Workflow Overview

You must read the documentation of the product at
Windows Workflow Foundation General Reference

The detailed list of classes at
Windows Workflow Foundation Class Library

In these  articles, Dino Esposito gives an introduction to WWF, with WinForm and ASP.NET examples:
Cutting Edge: Windows Workflow Foundation
Cutting Edge: Windows Workflow Foundation, Part 2

Hosting Windows Workflow
WWF runs in a host. In this article, you’ll find a detailed explanation of the alternatives to host a WWF runtime.


Enterprise _NET Community Manage Application Processes with Windows Workflow Foundation

Will work for process: Create and run WF workflows

A new article from Microsoft:
Web Service Workflows Deploy Distributed Business Processes With Windows Workflow And Web Services — MSDN Magazine, October 2006

WWF can persist the status and tracks the workflow instance history. An interesting discussion at:
WWF Persistance Status

You can write state machine-based workflows:
State Machines In Windows Workflow

Bart De Smet has a blog category on WWF, with articles:

Getting started with Windows Workflow Foundation (WF)

How to make a workflow dynamic – Part 1

How to make a workflow dynamic – Part 2

Exposing a workflow through a web service

Exposing a workflow via WCF

Tom Lake, who worked on the WWF SDK, has a lot of information, about custom activities, XAML activation, and WWF in general. Some articles:

Assorted Windows Workflow  XAML activation and how to use it

Switch Activity

Basics of Working with Custom Types in Workflow

Assorted Windows Workflow  Do you want to invoke another workflow but you won’t know which one until runtime

Assorted Windows Workflow  Do you need to launch another process from your workflow

Assorted Windows Workflow  How to set activity property from a custom input form

Assorted Windows Workflow  Couple of custom activities that you can use to synchronize branches of a ParallelActivity

Assorted Windows Workflow  Have you had problems using the FileWatcher sample in a StateMachineWorkflow or WhileActivity

Assorted Windows Workflow  How to send data to a workflow

Assorted Windows Workflow  Project template for XAML Activation Console Application

Assorted Windows Workflow  Examples of using Persistence and Tracking in ASP_NET

Assorted Windows Workflow  Using XAML activation in ASP_NET with a StateMachineWorkflow

The workflow implementation has a rule engine. Some links about this subject:

Introduction to the Windows Workflow Foundation Rules Engine

Windows Workflow: Rules and Conditions

WWF: Comparing WWF rules and the Microsoft Business Rule Engine–Comparing-WWF-rules-and-the-Microsoft-Business-Rule-Engine.aspx

WF: Comparing WF rules and the Microsoft Business Rule Engine

Rules Examples
Examples from Microsoft. Some special ones:

External Ruleset Demo (beta 2.2)
The External Ruleset Toolkit demonstrates how to store rulesets in an external SQL Server database and load them at runtime for use by a Policy activity.

Rules Driven UI
This sample will demonstrate this capability by using rulesets to pre-populate fields, do cross validation and various calculations on a target Windows Form. We will also show rules features such as forward chaining in this sample.

About rule engines in general:

Use Rules In Your Applications
A Rules Engine class library with source code and documentation

Using a Rules Engine to separate Business rules from the application

Some interesting discussion at Microsoft forums:

Re Trouble with WebService and Persistence – MSDN Forums

Using the Rules Engine with complex data containers – MSDN Forums

Re 3 layered architecture – Where to house rules – MSDN Forums

More links about WWF

How to lock a workflow instance using SqlWorkflowPersistenceService?

Managing Workflow’s Lifecycle

Microsoft Windows Workflow Foundation (WWF)

Ajax based Workflow Monitor,guid,a423e010-647b-4a32-8dfe-071bf6f43705.aspx

Angel “Java” Lopez