We will start with taking a look at the basic structure of a workflow. A workflow consists of a set of activities that form a model to describe a real-world problem. Activities are the building blocks of a workflow; every single step within a workflow requires an activity. Windows Work- flow 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 drives the flow of a workflow. The rule activity is also called a data-driven activity. An example of this type of activity is the EventDriven activity.
Out of the box, the Windows Workflow Foundation framework contains a default 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. Table 4-1 shows the activities that are included out of the box in Windows Workflow Foundation.
Table 4-1. Out of the Box Activities
Name Description
CallExternalMethodActivity This activity is able to communicate with a local service and is often used in conjunction with the HandleExternalEvent activity.
CodeActivity This activity lets you add custom logic to a workflow in the form of code written using VB.NET or C#.
C H A P T E R 4 ■ W I N D O W S W O R K F L O W F O U N D A T I O N 145
CompensateActivity If possible, this activity lets you undo actions that are already performed once an error occurs during workflow execution. If it is not possible to undo a given action, this activity can be used to call code that starts some kind of compensating action that responds to the workflow failure.
CompensationHandlerActivity This activity aggregates one or more compensating activities. This activity is typically used in conjunction with CompensateActivity and TransactionScope activities. ConditionedActivityGroup This activity lets you aggregate one or more child activities
that are executed conditionally. The child activities can be executed based on some kind of condition that applies to the ConditionedActivityGroup activity itself; it is also possible that a child activity is executed based on a condition that only applies to the child.
DelayActivity This activity lets you incorporate delays into workflows that are based on time-out intervals.
EventDrivenActivity This activity aggregates one or more activities that handle a specific event.
EventHandlersActivity This activity allows you to associate events to response handlers. EventHandlingScopeActivity This activity aggregates child activities and decides if event
handling is supported when those child activities are executed. FaultHandlerActivity This activity provides an exception-handling mechanism
within workflows.
FaultHandlersActivity This activity aggregates multiple child activities of type FaultHandlerActivity, thus providing an exception-handling mechanism within workflows.
HandleExternalEventActivity This activity is able to communicate with a local service by handling an event that is raised by such a service and is often used in conjunction with the CallExternalMethod activity. IfElseActivity This activity supports the ability to add decisioning mecha-
nisms to a workflow. Such activities test for a condition and perform activities that are a part of the first branch that matches the conditions.
IfElseBranchActivity This activity represents a specific branch of an IfElseActivity activity.
InvokeWebServiceActivity This activity allows you to add Web service communication within a workflow.
InvokeWorkflowActivity This activity allows you to invoke another workflow within your workflow.
ListenActivity This activity is a composite activity that aggregates child activities of the EventDriven activity type.
ParallelActivity This activity can be used to add parallel processing power (multithreading) to your workflows. This activity allows you to add two or more child Sequence activities that are executed concurrently by the ParallelActivity activity.
Table 4-1. Out of the Box Activities (Continued)
Name Description
146 C H A P T E R 4 ■ W I N D O W S W O R K F L O W F O U N D A T I O N
PolicyActivity This activity represents a collection of rules. Each rule within the collection consists of conditions and resulting actions. ReplicatorActivity This activity lets you create single child activities.
SequenceActivity This activity lets you link multiple activities together that are to be executed sequentially.
SetStateActivity This activity lets you specify a transition to a new state if you are creating a workflow that contains multiple states. StateActivity This activity lets you represent each separate state in a state
machine type of workflow.
StateFinalizationActivity This activity aggregates child activities that are executed whenever a StateActivity activity is finished executing. StateInitializationActivity This activity aggregates child activities that are executed upon
entering a StateActivity activity.
SuspendActivity This activity lets you temporarily suspend the operation of a workflow. You might want to do this if there is some kind of event or error condition that requires special attention. SynchronizationScopeActivity This activity aggregates activities that are executed sequen-
tially in a synchronized domain.
TerminateActivity This activity allows you to end workflow execution immediately. You might want to do this if an irrecoverable error condition occurs.
ThrowActivity This activity is part of a larger exception-management framework that allows you to implement an error-handling mechanism in your workflows. This activity allows you to throw exceptions to signal unexpected conditions in your workflow.
TransactionScopeActivity This activity allows you to implement an error-handling mechanism in your workflows.
WebServiceFaultActivity This activity is used to represent errors that occur during communication with a Web service, thus allowing you to model such events.
WebServiceInputActivity This activity is able to receive data from a web service. This activity is essential if you want to implement web service communication into your workflows.
WebServiceOutputActivity This activity is able to respond to a web service request made during the interaction between a workflow and a web service to a workflow. This activity is essential if you want to imple- ment two-way interaction between web services and workflows. WhileActivity This activity adds conditional logic to your workflows that
enable a workflow to loop until a given condition is met.
Table 4-1. Out of the Box Activities (Continued)
Name Description
C H A P T E R 4 ■ W I N D O W S W O R K F L O W F O U N D A T I O N 147
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.
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 work- flow 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. Figure 4-1 shows a basic workflow that consists of several activities and uses custom activity libraries.
Figure 4-1. Workflow with activities