Windows Workflow Foundation (WF) forms the basis of the SharePoint 2007 workflow functionality. Windows Workflow Foundation is a part of the Microsoft .NET Framework 3.0.
Note: The Microsoft .NET Framework 3.0 was formerly known as WinFX. It adds four new technologies to the
.NET Framework 2.0: Windows Workflow Foundation, Windows Communication Foundation (WCF, formerly known
as Indigo), Windows Presentation Foundation (WPF, formerly known as Avalon), and Windows Cardspace (WCF,
formerly known as InfoCard).
Windows Workflow Foundation is not a stand-alone application; instead, it has a run-time workflow engine that can execute short-term as well as persistable workflows. The Windows Workflow Foundation run time provides additional services that are important for executing workflows such as tracking, notifications, and transactions.
Any application or service can leverage WF workflow services by hosting WF in its process. SharePoint 2007 acts as a host for WF and adds a couple of custom implementations for workflow services as well.
SharePoint 2007 offers two different tools for working with and creating workflows: SharePoint Designer 2007 and Visual Studio 2005 Designer. Both will be discussed in this chapter. SharePoint Designer 2007 is a great tool for creating ad hoc workflows. It places the tools to create workflows well within the grasp of normal information workers. Visual Studio 2005 Designer, on the other hand, allows developers to create advanced, enterprise-level workflows.
Note Actually, you can associate a workflow created in SharePoint Designer with more than one list. The
auto-generated code contains hard-coded GUIDs representing a list. If you change those GUIDs, it is possible to
associate a workflow with another list.
In the following sections, we will delve deeper into the concepts related to Windows Workflow Foundation.
Activities
I will begin by looking at the basic structure of a workflow. A workflow represents a business process that consists of a set of transactions which form a model to describe a real-world problem. Business transactions form the elementary building blocks of a business process. A business transaction involves two parties:
• The initiator is responsible for starting a business transaction by issuing some sort of
request.
• The executor is responsible for performing some kind of action based on a request.
Conceptually, the life cycle of a business transaction consists of three phases:
1. Order phase: This phase starts when the initiator makes a request for some kind of action to
be performed. This phase ends with a promise by the executor to perform that action.
2. Execution phase: In this phase, the executor performs the requested action. The action succeeds
or fails. Either way, a result is reached, thus ending this phase of the business transaction
life cycle.
3. Result phase: In this phase, the executor communicates which result was reached, which is
either accepted or rejected by the initiator.
In Windows Workflow Foundation, the abstract concept of business transactions (a concept that has meaning in the external world) is translated to activities (a concept that has meaning in the software world). Activities are the building blocks of a workflow; every single step within a workflow requires an activity. Windows Workflow Foundation utilizes three different kinds of activities:
• Simple activity: A simple activity represents a simple action in its most basic form. An example of such a simple activity is the DelayActivity.
• Composite activity: A composite activity is an activity that aggregates one or more child activities within a single activity. An example of such a composite activity is the IfElse activity.
• Rule activity: A rule activity (also called a data-driven activity) drives the flow of a workflow. An example of this type of activity is the EventDriven activity.
Out of the box, the Windows Workflow Foundation framework contains a set of activities that provide functionality for the creation of workflows that contain control flow, conditions, event handling, and state management, and are able to communicate with other applications and services.
If you design a workflow, you can choose to make use of one of the activities belonging to this default set or you can create your own activities. Developers are free to create their own custom activity libraries and use them in other workflows. You can also use code activities to add custom code to a workflow. Code activities allow you to add basic behavior to a workflow; if you want complex behavior, such as the ability to create a composite activity that is able to contain other activities, you should create your own custom activity.
Activities can be sequential, in which case the order of workflow actions is specified at design time. Alternatively, activities can be event-driven. In such scenarios, the order of workflow actions is determined at run time in response to external events. Each activity contains the following logic/data:
• Metadata responsible for describing design time properties of the activity.
• Instance data describing the activity run-time state.
• Activity behavior in the form of programmed execution logic.
• Validation logic that can be used to validate activity metadata. This is optional.
Following figure shows a basic workflow that consists of several activities and uses custom activity libraries.

Components
Windows Workflow Foundation provides services as well as a framework and consists of the following
components (see Figure):
• Base activity library: This library contains all activities that are available out of the box.
Activities are essential building blocks for creating custom workflows and are discussed in the previous section, “Activities.”
• Runtime engine: The workflow runtime engine is able to interpret and execute workflows created using Windows Workflow Foundation. The runtime engine is also responsible for keeping track of workflow state.
• Runtime services: The WF workflow runtime engine can be hosted by different host applications, including SharePoint. This is a very flexible system, which is made possible via the workflow runtime services. The workflow runtime services are also responsible for handling any communication between the host application and the workflow.

Windows Workflow Foundation ships with a couple important tools that facilitate workflow creation: a visual designer and a debugger.
The workflow runtime engine is hosted in-process within a host application (never as a stand-alone process) and is responsible for creating and maintaining running workflow instances. For each application domain (in .NET, the fundamental process that executes code), there can be only one workflow runtime engine. A workflow runtime engine is able to run multiple workflow
instances concurrently. The runtime engine needs to be hosted by a host process, such as a console application, Windows form-based application, ASP.NET web site, or a web service. Because a workflow is hosted in-process, it can easily and efficiently communicate with its host application.
The workflow runtime engine utilizes many WF services when a workflow instance runs. The following services are included in the runtime engine:
• Execution
• Tracking
• State management
• Scheduler
• Rules
Besides the runtime engine itself, WF contains multiple runtime services. Runtime services are pluggable, so applications can provide these services in unique ways within their execution environment.• Tracking
• State management
• Scheduler
• Rules
Workflow Styles
Windows Workflow Foundation supports two styles of workflow: sequential and state machine. Before you start creating a workflow project, it is important to figure out what style of workflow you want to use.
The sequential workflow style is used for repetitive operations such as designing a set of activities that must always be performed in the same order. The workflow follows the sequence until the last activity is completed, and the workflow always remains in control of what happens next.
Such workflows are not necessarily entirely deterministic; you can use branching logic such as IfElseActivity activities or ParallelActivity activities and let the exact sequence of events vary.
For example, imagine you are creating a workflow that describes the process of installing software. This is a typical scenario where you always follow the steps one by one and in the same order.
Therefore, you can represent this process using a sequential workflow. The following figure shows an example.

The state machine workflow style is used when you want to model your workflow as a state machine. State machine workflows are made up of different states, one being the starting state, which is the state that is entered once the workflow process begins. Each state can receive a certain set of events. Based on these events, the workflow can transition from one state to another
state. In state machine workflows, the end user is always in control. That is why this type of workflow is also known as a human-oriented workflow. It is not required to define a final state, but if you do happen to have a final state in a workflow and the transition is made to that state, the workflow will end.
An example of a state machine workflow is an online shop where one state of the workflow process describes the situation where the customer can submit an order and wait for approval of the credit card data. Another state in the workflow process describes the situation where the customer, for the time being, is satisfied with selecting a couple of products and wants to place
the order at a later time. Therefore, each customer finds himself in one of the states in the workflow process and goes to another state depending on his choices.
The following Figure shows a statemachine workflow.

Although you certainly can, you do not have to rush out and start creating your own workflows immediately, because, out of the box, SharePoint 2007 ships with a set of default workflows. They are..
Approval :
This is probably the most basic and often-used workflows you can imagine. You can submit a document for approval; approvers can accept or reject a document or request changes.
Collect Feedback: Gathers feedback information from a group of reviewers.
Collect Signatures: Collects signatures from a group of approvers and requires the use of Microsoft Office clients.
Disposition Approval: Centered on document expiration and retention.
Group Approval: An advanced version of the Approval workflow.
Issue Tracking: Dedicated to an issue process involving tasks, task assignments, and task completion.
Translation Management: Facilitates a translation process involving documents, tasks, and translators.
Three-state: Tracks the status of an item through three states.
In my next posting, we will take a close look at implementing workflow in sharepoint.
In my next posting, we will take a close look at implementing workflow in sharepoint.


