WF Tutorial

Intertech Tutorials

WF Tutorial Objective


.NET 3.0 introduced a new API termed Windows Workflow Foundation, or simply WF. This API enables you to model and then execute business processes directly in your .NET assemblies. Using tools such as Visual Studio, you are able to build workflows visually. At runtime, this same workflow will be executed by the WF runtime engine.

In this chapter, you will be presented with a tour of the major components of the WF API, including WF activities, the WF runtime engine, and Visual Studio project templates and tools. This chapter will serve as the foundation for the remainder of the course.

The Motivation Behind WF

Most applications must be able to model various business processes. Simply put, a business process is a conceptual grouping of tasks that work logically as a collective whole. A given business process consists of a number of steps, substeps, and often further substeps that represent the entirety of the process.

Assume you are building an application that enables a user to purchase a product online. Once the user submits the order, a large number of activities are set in motion. Take these, for example:

Collectively, all of these tasks could represent a single business process.

Historically speaking, modeling a business process was yet another detail that programmers had to account for. This entailed authoring custom code to ensure that the application not only modeled but executed a business process correctly. Programmers needed to author additional code to account for points of failure, tracing, logging support (to see what a given business process is up to), persistence support (to save the state of long-running processes), and more. As you may know firsthand, building this sort of infrastructure entailed a good deal of manual labor.

Even after a development team built a custom business process framework for their applications, their work was not yet complete. A raw code base cannot be easily explained to nonprogrammers on the team who also need to understand the business process. Subject matter experts (SMEs), managers, salespeople, and members of a graphic design team often do not speak the language of code.

Given this, developers were required to make use of other modeling tools (such as Microsoft Visio) to represent the process graphically using skill set-neutral terms. The obvious problem here was having two entities to keep in sync. If developers changed the code, they would also need to update the diagram and vice versa.

The release of .NET 3.0 provided the Windows Workflow Foundation (WF) API. WF enables programmers to design business processes declaratively using a prefabricated set of activities. Rather than authoring reams of code to represent a given business process and the necessary infrastructure, developers can make use of the WF designers of Visual Studio to create the business process at design time. In this respect, WF facilitates building the skeleton of a business process, which can be fleshed out through custom code.

When programming with the WF API, a single document can be used to represent the overall business process, as well as the code that drives it. As a single WF document is used to represent the code driving the process, as well as a friendly visual representation of the process, you no longer need to worry about multiple documents falling out of sync. Better yet, this WF document will clearly illustrate the process itself and can be very useful to the nonprogrammers on your team.

There are many compelling reasons to make use of the WF API, rather than rolling your own infrastructure. Consider:

Be aware that the WP API can be integrated into any sort of .NET application. Desktop applications (console programs, Windows Forms / WPF UIs) can host workflows. ASP.NET applications can use workflows within a page on a web server. XML web services / WCF services can use and expose workflows. .NET class libraries can contain workflows to be reused at a binary level.

Even though the WF API can be used within any .NET application, Windows Workflow Foundation is certainly targeted at business apps. Business process management, application flow management, and document management are prime candidates for the WF API. Video games, multimedia applications, and OS extensions may not find the WF API very useful. Choosing when to incorporate WF into your projects is yet another design issue to contend with.

Copyright (c) 2008-2013. Intertech, Inc. All Rights Reserved. This information is to be used exclusively as an online learning aid. Any attempts to copy, reproduce, or use for training is strictly prohibited.