Windows Workflow Foundation
This article may be confusing or unclear to readers. (October 2007) |
This article may be too technical for most readers to understand.(January 2009) |
Windows Workflow Foundation (WF) is a Microsoft technology for defining, executing, and managing workflows. This technology was first released in November 2006 as a part of .NET Framework 3.0. The current version (4.0) was released as part of the .NET Framework 4.0. The major refinement of the new version is the tighter integration of WF with Windows Communication Foundation.
A workflow based program is like traditional programs that allow you to coordinate work and perform operations but has some important differences:
- Workflows use a declarative model (see Declarative programming) of writing programs by linking together pre-defined activities rather than an imperative programming model of writing each line of code
- Workflows can handle long-running work by persisting themselves to a durable store, such as a database, when idle and loading again once there is work to be performed
- Workflows can be modified dynamically while running when new conditions require a workflow to behave differently than when it was created
- Workflows provide a distinct separation of business rules and host application code making it easier to modify the business rules
- Workflows support sequential workflows for systems with sequential logic and state machine workflows for systems with event-based logic
- Workflows usually have a visual counterpart that allows a flowchart-like description of their logic
Microsoft has indicated that WF is going to be a cornerstone of their future Service Oriented Architecture platform announced in October 2007 with the codename Oslo.
There are two types of workflow, "Sequential" and "State Machine" [vague]. A Sequential workflow runs from beginning to end, with the workflow engine initiating each step. A State Machine workflow is driven by external events and user interaction, and simply constrains or interacts with those events, so it stores state between events. Both types can have branches and loops.
The .NET Framework 4.0 introduces a significant amount of change from the previous versions.
Usage / Scenario
Applications that perform / enable users to follow a "business process" which is a wizard like sequential flow of steps that must be taken in a specific order have been identified as the up and coming norm for Line Of Business (LOB) applications. These are applications that meet the specific needs of a given scenario within a business and are specific to the needs of the business. Workflow foundation (usually referred to as "dub F") is Microsoft's solution to providing the developer with a somple "framework" for building applications that fit such a scenario.
Consider a call centre, the people answering the phones must obtain key information from the caller before any action can be taken to assist the caller, such as identifying the caller and obtaining some detail about why they are calling. Typically in the past this would be a script that the phone answering personnell would follow, workflow WF allows the caller to follow an on screen a pre scripted path to asking the right questions and in turn populating the system with the correct information to enable the business to continue with the callers request in structured wizard like manner that is in line with the process defined at the management level. Such an approach prevents the user from straying off course but also advizes the user of any key information that may be of help along the way, such applications using the WF are capable of directing the user to different outcomes based on business rules in the same way as you would expect by following a workflow based on business rules
Process driven applications of this nature are thus made smarter by being built in line with "business rules" that business managers can specify and provide the developer with, meaning the whole organisation is then naturally standardised in its way of doing business.
Authoring Workflows
This is usually done at a senior level by developers and business analysts as a result of feedback from the business management outside of IT, the team are then responsible for "computerising" a business process. This is a complex undertaking and junior staff are not usually equipped with the dynamic thought patterns / skills required. This also involves in depth knowledge of the business and the intended processes to be built.
Workflows are defined in XAML, but are usually edited graphically in Visual Studio. However, the workflow may also be expressed in code using any .NET-targeted language (VB.NET, C#, C++/CLI, etc.).
WF provides .NET developers with the ability to separate the business logic of their application from the underlying execution components. This provides a clearer and more manageable representation of an application. This approach lends credence to the growing process-driven application methodology which aims to separate an application's logical flow from its executable components at an enterprise level.
Each workflow consists of one or more activities that each perform a separate and discrete piece of logic. Developers can write their own custom activities and then use them in workflows. WF also provides a set of general-purpose activities that cover several control flow constructs such as if-else logic, parallel processing, looping logic, etc.
Windows Workflow Foundation is supported by a companion set of extensions to Visual Studio 2005. These extensions contain a visual workflow designer which allows users to design workflows, a visual debugger which enables the users to debug the workflow designed, and a project system which enables the user to compile their workflows inside Visual Studio 2005. In Visual Studio 2008 the WF functionality is included without any extensions to install.
Moving data through Workflows
Activities that require or provide data can use properties to access or set this data. This is performed by binding the properties to a dependency property on a per activity basis.
The WF Runtime
Starting with .NET Framework 3.0 a WF Runtime is provided that includes common facilities for running and managing the workflows, providing feedback on the progress of workflow execution, and hosting individual workflow instances.
The WF Runtime can be hosted in any CLR application domain, be it a Windows Service, a Console, GUI or Web Application.
WF Runtime Services
The Workflow Runtime provides the ability to register services to be run inside it. The WF Runtime provides a set of core services that handle thread scheduling, persistence, transaction handling, queueing, and tracking. All of these except for the queueing service can be overridden.
Microsoft provides built-in persistence and tracking services. Both of these will write to a SQL Server database.
WF Runtime Local Services
The Workflow Runtime allows user-created services to be run inside it; these are called local services. A local service can serve just about any purpose, such as providing runtime communication between the workflow instance and the host application, which is the most commonly used purpose.
Every local service is implemented as a C# interface that is decorated with the ExternalDataExchange
attribute.
Calling a local service is a multi-step process:
- First use the
GetService
function to retrieve a reference to the local service. - Next use the
CallExternalMethodActivity
activity to call the local service.
Communicating with Workflows
WF provides several ways to communicate with a running instance of a Workflow:
- A Windows Communication Foundation approach to workflow communication was added in .NET Framework 3.5. This functionality comes in the form of two activities, SendActivity and ReceiveActivity, which send and receive WCF messages respectively. Workflows which include a ReceiveActivity expose a selected interface method as a WCF service. This could allow external code to, for example, make a Web Services call to a running workflow instance. The WF Runtime provides infrastructure to ensure that if a WCF call is made to a workflow instance that is in a persisted state (i.e. waiting for some external event like a WCF call or a timer event), then the instance will be reloaded into memory so that the message can be delivered to the workflow instance. Workflows which include a SendActivity are able to call external services via WCF.
- When a workflow instance is created, the host application can provide arguments as Dictionary objects. These objects can be treated as both an input and an output to the workflow.
- WF also allows the workflow to update the host application through the WF Runtime of the progress of the workflow's execution. This is done by raising events in the WF Runtime to which the host application will subscribe. This includes the starting and ending of each workflow instance or moving into an idle or persisted state.
Types of Workflows
Using the WF foundation, three different types of Workflow can be created:
- Sequential Workflow (Typically Flow Chart based, progresses from one stage to next and does not step back)
- State Machine Workflow (Progress from 'State' to 'State', these workflows are more complex and return to a previous point if required)
- Rules-driven Workflow (Implemented based on Sequential/StateMachine workflow. The rules dictate the progress of the workflow)
Products Using Workflow Foundation
- Microsoft Office SharePoint Server from the 2007 release. Versions prior to 2007 did not use WF.
- Microsoft Speech Server from the 2007 release. Versions prior to 2007 did not use WF.
- Microsoft Dynamics CRM from the 4.0 release. Versions prior to 4.0 did not use WF.
- Microsoft Dynamics AX from the 2009 release. Versions prior to 2009 did not use WF.
- Laserfiche Workflow from the Laserfiche Workflow 8.0 release.
- PowerWF - converts PowerShell Scripts into workflows, and vice-versa. Built in support for PowerShell v1.0 and v2.0 and VMWare PowerCLI.
- Team Build from the 2010 release, for the definition of build processes
- FRENDS Iron - Hosts, schedules, monitors and manages Window Workflows
- JAMS Scheduler Designs, schedules, and monitors Windows Workflows.
WF Related project types in Visual Studio 2008
- empty workflow project
- sequential workflow library
- sharepoint 2007 state machine workflow
- state machine workflow library
- sequential workflow console application
- sharepoint 2007 sequential workflow
- state machine workflow console application
- WorkFlow activity library
- Activities like(Delay Activity)
Books
- Dharma Shukla, Bob Schmidt: Essential Windows Workflow Foundation, Addison-Wesley Professional, 13 October 2006, ISBN 0-321-39983-8
- Michael Stiefel: Building Applications with Windows Workflow Foundation (WF): Basics of Windows Workflow Foundation (Digital Short Cut), June 5, 2007, Kindle, ISBN 0-321-51454-8
- Brian Noyes: Developing Applications with Windows Workflow Foundation (WF) (Video Training), June 7, 2007, Brian Noyes, ISBN 0-321-50313-9
- Brian R. Myers: Foundations of WF, Apress, 23 October 2006, ISBN 1-59059-718-4
- Bruce Bukovics: Pro WF: Windows Workflow in .NET 3.0, Apress, 19 February 2007, ISBN 1-59059-778-8
- Todd Kitta: Professional Windows Workflow Foundation, Wrox, 12 March 2007, ISBN 0-470-05386-0
- Kenn Scribner: Microsoft Windows Workflow Foundation Step by Step, Microsoft Press, 28 February 2007, ISBN 0-7356-2335-X
Localised links
- Windows Workflow Foundation
- MSDN Library: Windows Workflow Foundation
- Hands On Lab: Introduction To WF4
- Workflow Foundation blog Template:Sv