Introduction

I have spent half of my career focused on business and the other half focused on software development. I am—through my business persona—driven by efficiency. Whereas software has led to tremendous efficiency gains, to say the least, it has also left tremendous room for improvement. Applications are hard to create, understand, and change. My quest for more efficient ways to create software led me to business process management a few years back. After watching the BPM and workflow industry for a couple of years, I was very excited when I learned of Windows Workflow Foundation (WF). After learning more about WF, I became more excited and decided to write this book.

I am convinced that we are entering a new phase of software development and that—on the Microsoft platform—WF lies at its core. Let’s look at the key benefits WF will drive:

Image   Simplified development and improved process comprehensibility are delivered because workflows are graphically created and therefore inherently self-evident.

Image   There is a built-in infrastructure to monitor running processes that supplies runtime transparency. The same graphical diagram that runs the workflow is used to illustrate its current step, previous executed steps, and potential completion paths.

Image   There is improved runtime flexibility because WF processes can be loaded at runtime from a database and executed without precompilation. Running processes can be changed. An individual running order, for instance, can have an additional approval step added to facilitate unexpected regulatory concerns.

Image   Simplified and powerful state management is provided. The workflow engine keeps track of the current process step, idles and persists as necessary, and restarts the workflow when appropriate. The workflow engine also allows for interrupting the prescribed process flow and skipping or redoing a step. For instance, it offers tools to transition an order to the earlier customer service step from the shipping step.

Image   Domain-specific languages can be created by adding a collection of custom activities (WF building blocks) and potentially a custom workflow designer as well.

Image   Cloud Service Infrastructure is provided. WF’s integration with WCF permits it to expose itself across the cloud and to access cloud services securely and reliably. When accessing multiple cloud services from a workflow, it becomes a cloud service composition platform.

The goal of this book is twofold: first, to explain what WF is, its value, and how and where its features fit into the product’s overall goal; second, it drills these concepts into you with pervasive hands-on labs. At the end of this book, you should be well-schooled in the “why” and the “how” of WF.

Book Target Audience

This book is targeted at all levels of .NET developers. It covers most aspects of WF. The labs walk you through the exercises step by step. It is appropriate for beginning .NET developers because of the step-by-step nature of the labs. It is appropriate for intermediate and advanced .NET developers because it covers a substantial amount of material that more advanced developers can take time to digest more thoroughly. All developers will also much better understand the “why” of WF. It is much more than a tool to use to create executable diagrams.

How This Book Is Organized

Each hour in this book, with the exception of Hour 1, is packed full of hands-on labs. When a new topic is introduced, it is first explained. The first time an item appears in a lab, you walk through each step and the item is explained in or near where it first appears. When the item appears again later in the hour or in a new hour, it is generally not re-explained. The lab, however, will almost always walk you through the steps to perform the task—although maybe in less detail. The reason I walk you through steps again (and sometimes again) is based on my own experience. I frequently am absorbed learning a new topic and do not want to divert the mental resources from learning the task at hand to remembering or looking up past topics. A contrary viewpoint is that not rewalking through the steps each time a topic reappears in a subsequent lab provides a better learning experience, because readers must learn how to perform the task on their own. This viewpoint is perfectly valid; when and if you want to take this approach, I recommend attempting to perform repetitive actions without reading step-by-step instructions.

Image

If you copy and paste code from the electronic version of this book, double-check how the quotes paste. Depending on your program, you might need to manually alter the quotes to make them compatible.

Hour Summary

In Hour 1, “Understanding Windows Workflow Foundation,” a conceptual overview of workflow is provided first. Then WF, the product, is covered in whole. Finally, WF’s main components are covered individually.

In Hour 2, “A Spin Around Windows Workflow Foundation,” you learn how to build a basic sequential workflow by dragging and dropping activities (WF’s building blocks) onto the workflow designer. You also learn to create workflows declaratively using XAML.

In Hour 3, “Learning Basic Hosting,” you dig into hosting a workflow. WF workflows run in the process spaces of another application, referred to as a host. You learn to register events to interact with the host and to register runtime services to change the host’s behavior.

In Hour 4, “Learning Host-Workflow Data Exchange,” you learn how to send data from the host to the workflow and vice versa. Workflows send data to the host via synchronous methods, and hosts send data to the workflow via asynchronous events.

In Hour 5, “Creating an Escalation Workflow,” you learn how to create a workflow that is accessed by two different hosts, which is a very likely scenario. The first host invokes the workflow and allows approval or rejection to be specified. If the process requires further (managerial) approval, the workflow is accessed from the second host.

In Hour 6, “Creating Basic State Machine Workflows,” you learn how to create StateMachineWorkflows. StateMachineWorkflows hold a series of states that each contains a collection of valid events. They are the second most popular type of workflow style (behind sequential workflows).

In Hour 7, “Creating Advanced State Machine Workflows,” you learn how to interact with the state machine workflow using capabilities available only to state machine workflows. These include accessing the current state and overriding the current state to perform the skip and rework pattern.

In Hour 8, “Working with Parallel Activities and Correlation,” you learn to perform tasks concurrently. The workflow runtime handles the logistics of performing the tasks in parallel (or interleaved, as you learn in the hour). You then reconfigure the approval workflow to call for concurrent approval, which requires learning about correlation.

In Hour 9, “Working with the Replicator and While Activities,” you learn to use activities that perform a task n number of times, where n is specified at runtime. The Replicator—one of WF’s advanced control flow activities—can perform the tasks sequentially or in parallel and also features an early termination clause. The While activity is similar to the C# while statement.

In Hour 10, “Working with EventHandlingScope and Strongly Typed Activities,” you learn to use the EventHandlingScope activity that allows one or more events to be received throughout the lifetime of the workflow, such as cancellation and approver maintenance.

In Hour 11, “Creating Data-Driven Workflows,” you learn to use the ConditionedActivityGroup (CAG) activity. The CAG is another advanced control flow activity. It allows concurrent processing, like the Parallel activity, with a few additions. Most noteworthy, each branch has a When condition, and the CAG has an overall Until condition.

In Hour 12, “Working with the WF RuleSet,” you learn to use WF RuleSet technology and add-on products to access RuleSets from a database. RuleSets are a collection of rules that can be prioritized and configured to reevaluate in case a dependent rule changes. Each rule in a RuleSet has a Then and an optional Else action. The first is executed when the rule evaluates to true and the second when it evaluates to false. You then work with third-party add-ons that allow RuleSets to be stored and analyzed in a database and loaded at runtime.

In Hour 13, “Learning to Track Workflows,” you learn to monitor running workflows. First, the tracking architecture is covered. Then you learn to create custom tracking profiles to filter the information that is tracked. Then you learn to augment the extracted information with business information, such as the order number and order amount. This information is useful to produce more meaningful reports and create alerts when, for example, the order amount falls below a threshold amount.

In Hour 14, “Working with Roles,” you learn to control access to the workflow. Each incoming event can be wired to an Active Directory or ASP.NET role provider. Then only users existing in the role provider are permitted access.

In Hour 15, “Working with Dynamic Update,” you learn to modify running workflows. Activities can be added and removed, and declarative rules can be changed. Changing running workflows are one of WF’s primary capabilities. Using this capability in conjunction with WF’s tracking is particularly intriguing.

In Hour 16, “Working with Exceptions, Compensation, and Transactions,” you learn to trap and handle errors and to create transactions. Exceptions and transactions work similarly to the way they work in standard .NET. Compensation is a WF-only capability that is used to correct already completed work in WF.

In Hour 17, “Learning Advanced Hosting,” you learn to use most workflow events to control the workflow from the host, add additional capabilities to alter the workflow runtime, and invoke another workflow from a workflow. You will experiment with the suspended, aborted, and other events. You will add runtime services that control transactions, threading, and other functions. Finally, you learn to call a workflow from another workflow.

In Hour 18, “Working with Web Services and ASP.NET Hosting,” you learn to expose a workflow as a web service, call a web service from a workflow, and to run workflows from ASP.NET.

In Hour 19, “Learning WF-WCF Integration,” you learn to integrate WF with Windows Communication Foundation (WCF), Microsoft’s new distributed technology. WCF can expose WF workflows as services accessible in the cloud and can be used to call out to services from WF workflows. These two products appear to be merging into one unified application server.

In Hour 20, “Creating Basic Custom Activities,” you begin to create your own custom activities. In WF, you are not limited to the activities provided out-of-the-box. Custom activities are a major part of WF. Therefore, five hours are devoted to them. In this hour you will create Customer and CreditCheck activities that encapsulate this “domain” functionality in activities that can be placed on workflows just as can be done with the activities that ship with WF.

In Hour 21, “Creating Queued Activities,” you learn to create activities that execute in multiple bursts and to work with WF’s queuing system, which underlies all WF communication.

In Hour 22, “Creating Typed Queued and EventDriven-Enabled Activities,” you learn to strongly type the data accessed in queues and to create a special type of queued activity called an EventDriven activity.

In Hour 23, “Creating Control Flow Activities Session 1,” you learn to create activities that serve as placeholders for child activities and that schedule their child activities for execution. You can create your own control flow patterns that match the need of your domain. You can also implement general workflow patterns like those found at www.workflowpatterns.com.

In Hour 24, “Creating Control Flow Activities Session 2,” you also learn to implement compensation at the activity level. Then you implement activity validation. Finally, you learn to use attached properties that allow a property, such as a condition, to be passed down from a parent activity to a child activity.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.188.67