0% found this document useful (0 votes)
339 views31 pages

Windows Workflow Foundation (WF)

This document provides an overview of Windows Workflow Foundation (WF). It discusses what workflow and WF are, different workflow types like sequential and state machine workflows. It covers WF architecture including hosting, activities, built-in activities, runtime services, persistence, and tracking. Examples of sequential and state machine workflows are provided. The document demonstrates creating a simple workflow and custom activities. It also discusses compensating logic and transactions in workflows.

Uploaded by

Cao Xuan Duy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
339 views31 pages

Windows Workflow Foundation (WF)

This document provides an overview of Windows Workflow Foundation (WF). It discusses what workflow and WF are, different workflow types like sequential and state machine workflows. It covers WF architecture including hosting, activities, built-in activities, runtime services, persistence, and tracking. Examples of sequential and state machine workflows are provided. The document demonstrates creating a simple workflow and custom activities. It also discusses compensating logic and transactions in workflows.

Uploaded by

Cao Xuan Duy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Windows Workflow

Foundation
(WF)

Adam Cogan & Mark Liu


About Mark

• Senior Software Architect at SSW


• Specialises in
– ASP.NET 2.0
– Windows Workflow
– Windows Communication Foundation
– NHibernate / NetTiers / LINQ
– SQL Server 2005 (Reporting Service,
Integration Service)
Agenda

• Part I - Introduction to Windows Workflow


Foundation
– What is Workflow?
– What is Windows Workflow Foundation?
– Workflow Types

• Part II – Workflow Architecture


– Hosting architecture
– Built-in Activities
– Built-in Services
– Workflow Persistence
– Workflow Tracking
What is Workflow?

“Workflow is the operational aspect of a


work procedure: how tasks are structured,
who performs them, what their relative
order is, how they are synchronized, how
information flows to support the tasks and
how tasks are tracked.”

Source: http://en.wikipedia.org/wiki/Workflow
What is Workflow?

• It is a series of steps that makes up a business


process
• It can involve people
– I.e. Wait For Approval, Notify Manager
• It can co-ordinate software
– I.e. Check Inventory, Debit Account
• It organise them into flowchart or state diagram
• It can be short lived
– I.e. page control, automation
• It can be long lived
– I.e. online auction, approval process
Introduction to Windows Workflow Foundation

• It is a framework for rapid development of


workflow-enabled application
– Extensible Programming model
– Visual Designer Tool
• With Visual Studio 2005 and 2008
– Workflow Engine
• In-process workflow engine to support different
architecture scenario
Key concepts
Visual Designer

•Workflow is a set of Activities


A Workflow
•Workflows run within a Host
Process: any application or
server
•Developers can build their own An Activity
Custom Activity Libraries
• Base Activity Library: Out-of- Custom Activity Library
box activities and base for custom
activities Windows Workflow Foundation
• Runtime Engine: Workflow
execution and state management Base Activities Library
• Runtime Services: Hosting
Runtime Engine
flexibility and communication
• Visual Designer: Graphical and Runtime Services
code-based construction
Host Process
Workflow Types

• Sequential Workflow
– Looks like a flow chart

• State Machine Workflow


– Looks like a graph
Sequential Workflow

• Characteristics
– Start from the first activity
– Execute in sequence
• Limitation
– Cannot go back to previous activity
without adding Loop
– Cannot have two “go-back” loop that
intersect each other
– Inflexible when interacting with
external system, where event order
cannot be guaranteed
• Scenario
– Automation, Document Processing
Demo: Simple Workflow

• Create a Simple Workflow


– Create Workflow with Code Activity
• Create a Console Application
– Create Workflow Runtime
– Create HelloWorldWorkflow Instance
– Start the Workflow
State Machine Workflow

• Characteristics
– Event driven
• System to system,
• Human to system (via application)
– Execution based on current State
– More flexible for external changes
– Start with an Initial State and finishes when it reaches
Completed State
• Limitation
– Cannot create re-usable state activities
– Designer is buggy with Debugger
• Scenario
– Approval workflow with multiple approval level
Part II – Workflow Architecture
Hosting Workflow

• Workflows are managed and executed by


WorkflowRuntime
• WorkflowRuntime can be hosted by any
.NET processes
– Console
– Windows Forms
– ASP.NET
– Windows Service
Workflow Runtime

• Runtime Engine
– The core layer of the Workflow Runtime
– Responsible for execution and lifecycle of workflow
• Runtime Services
– Each service provides a feature that interact with system outside the
workflow
– Runtime Services provide features that interact with the Runtime
Engine
I.e.
• Persistence
• Tracking
• Scheduling
– Built-in runtime services can be overwrite by custom runtime services
I.e.
• Custom OleDbPersistenceService that implements IPersistenceService to store workflow
state into any OleDB database.
Activities

• Building blocks of workflow


– Represent unit of execution, re-use and composition
– Basic activities are steps within a workflow
– Composite activities contain other activities
• Activities are classes
– Properties and events are defined by activity author and
programmable from the workflow
– Inherit from System.Workflow.ComponentModel.Activity class
– Contain methods that are invoked by the Workflow Runtime
(E.g. Execute)
– Can be built into workflow assembly or deployed as re-usable
libraries
• Best Practice: keep workflow and activities in separate projects
Built-in Activities

• Control flow activities


– Sequence
– Parallel
– IfElse
– While
– ConditionedActivityGroup
– Replicator
Built-in Activities

• Transaction Activities
– Transaction Scope
– Compensatable Transaction Scope
• Error handling Activities
– Throw
– Fault Handler
• Can only be added to Fault Handlers in a Composite
Activity
Built-in Activities

• Lifetime activities
– InvokeWorkflow
– Suspend
– Terminate
• Event waiting activities
– EventDriven
– Listen
– Delay
– HandleExternalEvent
Built-in Activities

• Web service activities


– Invoke webservice
– WebServiceRequest
– WebServiceResponse
• Other
– InvokeExternalMethod
Demo: Building Custom
Activities

• Build a ConsoleWrite activity


• Update Hello World workflow
Introducing Compensating
Logic

• Transaction is not suited for long running


processes. You cannot lock a table for 3
days!

• Need a mechanism to reset committed


information when a problem is encountered

• For example
– Need to return inventory to stock when
customer cancel order
Activities with Compensation
Logic

Long-running workflow

Atomic Transaction

Get Item Queue DB Normal Execution

De-queue
Item Queue DB

Compensating Logic
Compensation Handler
Executed only if error occurs
Queue after the related transaction
Item Queue DB was properly submitted
Compensating Flow

Long-running workflow

Atomic Transaction 1 Compensation Handler 1

Get Item DB
Re-queue Item DB

De-queue Item DB

Atomic Transaction 2 Compensation Handler 2

Process Item DB Cleanup Item DB

• If transaction 1 commits and transaction 2 fails then compensation handler 1 will be


executed
• The item will be re-queued into the database
Runtime Services

• Workflow Loader Service


– Creates workflow instance based on class type or XML
definition
– Built-in: Default Workflow Loader Service
• Workflow Scheduler Service
– Allocate thread to the Runtime Environment to execute the
workflow
– Built-in: Default Scheduler Service
• The default scheduler service created by Runtime if none is specified
• Multi-threaded – create and manages it’s own thread pool to execute
workflows
• Used in Windows Form, Console and Windows Service apps
– Built-in: Manual Scheduler Service
• Single threaded – only use the thread donated by the caller
• Used in ASP.NET apps
Runtime Services

• Persistence Service
– Stores and loads workflow state into durable storage
– Built in: SqlWorkflowPersistenceService
• Store workflow state in SQL Server
• Database scripts can be found in:
C:\Windows\Microsoft.NET\Framework\v3.0\Windows Workflow
Foundation\SQL\EN
• Tracking Service
– Track state of the workflow
– Track execution history
– Built in: SqlTrackingService
• Support customizable tracking criteria
• Store tracking history in SQL Server
• Supports customizable tracking
• See above for database scripts
Runtime Services

• WorkflowCommitWorkBatchService
– DefaultWorkflowCommitWorkBatchService
• Uses MSDTC
– SharedConnectionWorkflowCommitWorkBatchS
ervice
• Tracking and Persistence schema must be on the same
database
• Avoid MSDTC by sharing database connection between
persistence and tracking
Workflow Tracking

• Generic API that allow application


developers to track:
– Execution status of the workflow / activities
– Properties in the workflow / activities
– User-defined track point inside the workflow
• Tracking are filtered by a Tracking Profile
Workflow Tracking

• Built-in SqlTrackingService provides:


– Store tracking data to SQL server
– Customizable Tracking Profile by WorkflowType
• No built-in designer
– Query objects to retrieve tracking data
• Limitation of SqlTrackingService:
– Stores data in an highly normalized and generic schema,
difficult to get a specific value for a workflow
– Lack of built-in designer to create custom tracking
profile
– Lack of built-in tools to view the tracked data
– There are sample code that does both
Demo: State Machine
Workflow

• case-study of a simple approval system


Contact Details

• adamcogan@ssw.com.au
• markliu@ssw.com.au
THANK
YOU!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy