How Windows Workflow Foundation Works
The WF engine architecture has three layers: hosting, runtime, and a workflow model. Workflow designers help prepare workflows and custom activities. For example, in Microsoft Office 2007, a workflow engine embedded in SharePoint integrates with Word, Excel, Outlook, and other Office applications to support document workflow activities.
The WF hosting layer contains the standard pluggable WF runtime services and any custom services that the programmer includes. The standard services are:
- Communications, for example with the host application and Web services.
- Persistence, the storage of state for long periods of time.
- Tracking, the interface to the instrumentation of workflows.
- Timers, which are durable clocks for managing potentially long delays.
- Threading, which manages the host thread pool for the workflow.
- Transactions, which implement compensating transactions so that operations can fail gracefully without corrupting the durable state of an application.
The WF runtime layer contains its core services, which are not
pluggable. These are the execution service, the core tracking service, the state management service, the low-level scheduler, and the rules service.
The WF workflow model layer supports two basic models: sequential workflows, and state machine workflows. Both types can have data-driven sections. In addition, developers can inherit from the workflow model classes to create customized models, or even create completely new model classes from scratch.
The basic difference between WF and a typical workflow engine is that WF is not tied to any underlying language. Instead, it consists of a set of simple and composite activities that it chains together and executes according to the model. You might think that the XAML markup for a workflow constitutes an XML-based language, but Microsoft views this more as data or serialized workflow state than as code.
The Visual Studio 2005 Extensions for Windows Workflow Foundation turns workflow design into a simple drag-and-drop exercise. In Figure 3, I dragged a code activity into a sequential workflow, then filled in one line of code in the code activity's handler, which prints "Hello, World!" If you build and run this application, it does indeed print "Hello, World!" in a console window, possibly setting a new world's record for the largest amount of tooling used to design this particular application.
|Writing Hello World as a workflow possibly sets a new world's record for the largest amount of tooling ever used to design this particular application.|
|Figure 3. Hello World as a Workflow: The figure shows the world's simplest example application written as a workflow.||
|Figure 4. Adding an IfElse Activity: Here's a sequential workflow in the designer after adding an IfElse activity.||
The three tabs at the bottom left of the Sequential Workflow pane select the view: the workflow activity, the workflow's cancellation handler, and the workflow's fault handlers.
The workflow gets more interesting as you add more activities. Figure 4
shows the designer after I dragged an IfElse
activity onto the design pane, but have not yet defined the decision criteria or what the branches will do.
Microsoft Office 2007 Workflow Integration
SharePoint 2007 Server hosts WF server, so that Office 2007 applications can use (and be used by) workflows. For example, a Word 2007 document might kick off a SharePoint workflow that sends an email requesting an approval to another user through Outlook, then resumes only when that user grants or denies the approval on a SharePoint page created for that purpose. Reviews, approvals, and document expiration are all standard 2007 Office workflows.
Office SharePoint Designer 2007, the successor to FrontPage, can design workflows, and developers can also use the 30-odd custom Office 2007 activities to design Office workflows in Visual Studio 2005. The InfoPath 2007 designer supports binding form elements to workflows.
The use of SharePoint 2007 makes developing people-based workflows much easier than it has been, since it combines workflow with the Office applications that people use daily.