Home > Articles > Operating Systems, Server > Microsoft Servers

Windows Workflow Foundation: March Through the Activities

  • Print
  • + Share This
Activities are the building blocks of a workflow. A number of activities are provided in the Visual Studio 2005 toolbox to create basic workflows. You can also easily create your own activities, which can be added to the toolbox for use in your workflows. This chapter introduces you to all the activities that come with Windows Workflow Foundation.
This chapter is from the book

In this chapter

  • Table of Activities

  • Control Flow Activities

  • Workflow Lifetime Activities

  • Event Waiting Activities

  • Transaction and Exception Activities

  • Data-Centric Activities

  • Web Services Activities

  • The Code Activity

  • State Workflow Activities

  • Custom Activities

Activities are the building blocks of a workflow. A number of activities are provided in the Visual Studio 2005 toolbox to create basic workflows. You can also easily create your own activities, which can be added to the toolbox for use in your workflows.

As such, activities are the first point of extensibility for Windows Workflow Foundation. Custom activities can be built that are treated the same as primitive activities that come with Windows Workflow Foundation. Also, custom activities can be built to relate to specific application domains for end-user applications. These custom activities, when targeted at a suitable higher level, could provide a nondeveloper design experience. You can build activities to be used with the workflow application that you build, or you can use activities that come from third-party software.

This chapter introduces you to all the activities that come with Windows Workflow Foundation.

Table of Activities

Table 3.1 provides a reference list of all the activities provided in the toolbox for Windows Workflow Foundation in Visual Studio 2005. This list is the same order as the Visual Studio 2005 toolbox; however, not all of these activities will be present depending on the workflow project template selected.

Table 3.1 Activities Provided in the Toolbox for Windows Workflow Foundation in Visual Studio 2005

Activity Name

Description

Sequence

Container for sequentially executed activities

Parallel

Two or more sequences executed in parallel

While

Repeats activities while condition is true

IfElse

Executes activities if a condition is true

Listen

Waits for one of a set of events

EventDriven

Used in a Listen or a workflow event handler to specify the event and contain the executed activities

Delay

Causes the containing branch of the workflow to wait for a timeout

ConditionedActivity Group

A list of activities executed on a variety of conditions

Replicator

Executes multiple copies of a contained activity

TransactionalContext

Contains activities involved in short- or long-term transactions

ExceptionHandler

Contains exception-handling activities

Throw

Throws an exception from a workflow or scope

Compensate

Used in an exception handler body to reference the required compensation

Code

Executes a specified method in the code-beside file

InvokeWebService

Makes a call out to a web service

InvokeWorkflow

Makes a call out to another workflow

UpdateData

Sends an instance of a predefined class of data to the host

SelectData

Requests an instance of a predefined class of data from the host

WaitForData

Accepts an instance of a predefined class of data from the host

WaitForQuery

Accepts a request for an instance of a predefined class of data from the host

WebServiceReceive

Waits for an external web service call to the workflow

WebServiceResponse

Sends a response to an external web service call from the workflow

Suspend

Stops the workflow instance from running; it can be restarted

Terminate

Shuts down this workflow instance

State

Defines a state in a workflow

StateInitialization

Contains activities that are executed on entering a state

SetState

Initiates a state transition in a state machine


Container for Activities

Some activities can act as a container for other activities. This is in addition to the workflows that contain activities. This list shows the main items that can act as containers of activities in the workflow designer:

  • Sequential workflow

  • State machine workflow

  • Exception handlers

  • Compensation

  • Event handlers

A few activities such as sequential workflows (a workflow is a special kind of activity) and TransactionalContexts have complex definitions that are presented as multiple views. These consist of the main sequence, exceptions, events, and compensation. The workflow designer provides access to these views through tabs and the context menu.

Figure 3.1 shows the tabs for the four views. You view each design surface by clicking on the respective tab. A Scope activity has the same selections in the context menu, which you access by right-clicking on it.

Figure 3.1

Figure 3.1 The tabs in the workflow designer from Visual Studio 2005.

Conditions

Several activities (While, IfElse, ConditionedActivityGroup, and Replicator) can have conditions or rules associated with them. Each condition returns either true or false. There are three possible condition types available:

  • Code condition: A specified method, which the developer writes, that returns true or false. This type of condition is compiled into the workflow.

  • Declarative condition: A single declarative condition that results in a true or false outcome. The declarative condition is interpreted and this allows it to be modified after the workflow is compiled. This is described in the next section.

  • Policy condition: A ruleset defined in a policy-derived activity consisting of a collection of conditions and resultant actions.

Any of these types of conditions can operate on shared workflow instance state in the workflow as described by public member variables. In each case a true or false result is fed back into the activity execution.

Declarative Condition

The condition property of an activity must be set to the type of condition being used. You select rules by setting the condition property to System.Workflow.Activities.Rules. RuleConditionReference. Once selected, a [+] symbol appears next to the condition property. You can click on this symbol to show the condition details. Click on the condition details to show the declarative condition that is associated with your workflow.

You can choose a declarative condition from the list, and add or edit declarative conditions in the list. Figure 3.2 shows the rules editor that displays when you add a declarative condition.

Figure 3.2

Figure 3.2 The Declarative Condition Editor.

In the Declarative Condition Editor you can add logical operators to the condition (AND, OR, and NOT). You can also add predicates. A predicate is a binary operator and two operands. The binary operators supported are ==, >, <, >=, and <=. Supported operands are constant value, arithmetic function, and scoped member, which refers to a workflow instance variable. You can specify the type for the comparison and you can compare to null or an empty string.

Complex conditions can be created based on workflow instance member variables.

  • + Share This
  • 🔖 Save To Your Account