CHAPTER 6
127
Windows Workflow
Foundation 4
Availability: Framework 4.0
Windows Workflow Foundation (WF) was first introduced in 2006 with .NET 3.0. It is probably fair to say
that WF didn’t receive the widespread adoption Microsoft was hoping for. This lack of uptake was
probably due to a number of factors:
• Although the WF designer offers a natural way of working, it is a very different way
of developing applications and contains a new API to master.
• Slow performance.
• Writing your own work flow activities was not as easy as it could be.
• Handling and passing data between activities was cumbersome
• Limited support for messaging scenarios and integration with WCF.
• Some developers were confused by the hosting model.
• A clunky designer interface made you want to poke your own eyes out (OK, it
wasn’t that bad but it wasn’t that good either).
Microsoft has aimed to address these issues and also to integrate WCF and WF closer than ever
before.
Why Use WF?
Before we look at how to use Microsoft WF you may be wondering why should I bother?
WF can greatly simplify the development of applications that deal with complex and long-running
Processes as traditional coding methods are not ideal for solving this type of problem.
To understand why they are not, let’s take the example of a visa approval system (loosely based on
my experience of the UK/Australian emigration process) as shown in the flowchart in Figure 6-1. CHAPTER 6 WINDOWS WORKFLOW FOUNDATION 4
Agggrahh! As you can see even a simple process can get very complex quickly. Of course you can
develop such an application very successfully (and many have) using current technologies, but Windows
Workflow has many inbuilt features to handle some of this complexity.
What Can Windows Workflow Do for Me?
Windows Workflow provides the following functionality out of the box:
• A visual method of constructing your applications similar to our flowchart in
Figure 6-1. This visual approach is more intuitive, can be easier to debug , is easier
to unit test with changes in this release (a controversial idea, but discussed in the
following sections), and can be understood by non-technical users. Of course
developing an application entirely in code has its advantages as well — it is
generally easier to test, and developers won’t have to learn new ways of writing
applications.
• More efficient use of server resources. Non-active workflows “sleep” and are
“rehydrated” when needed.
• Coordination and synchronization. Workflows that make calls to external services
may take weeks to receive a reply. By using correlation, we can ensure returned
calls are automatically directed to the correct instance of a work flow that can then
“wake up” and resume its work
• Workflow state can be persisted even during system down time and resumed
automatically.
• Ability to host the workflow designer within your applications for customization
and configuration by end users.
• Rich debugging and monitoring support.
• A common framework for workflow development on the Windows platform. WF is
already utilized in flagship products such as Microsoft Sharepoint and Dynamics
(note these use WF3 at time of writing). You can even host your workflows in
Microsofts cloud computing platform Windows Azure (at the time of writing this is
not available, but should be in the future).
• WF can assist you with versioning and updating issues (although for the forseeable
future this is never going to be that easy).
132
Workflow Designer
The designer (Figure 6-4) is used to piece together your workflow, and contains tools for debugging and
monitoring it.
Figure 6-4. Workflow designer
It is even possible to host the workflow designer within your application. For more information on
this please refer to the following links:
• http://msdn.microsoft.com/en-us/library/dd489440(VS.100).aspx
• http://channel9.msdn.com/learn/courses/VS2010/WCFWF/IntroToWF/Exercise-10-
Hosted-Designer/
The trident project (a tool for customizing scientific workflows) used this facility extensively. Take a
look at: http://connect.microsoft.com/trident/.