Windows Workflow Foundation (WF)
Windows Workflow Foundation (WF)
Foundation
(WF)
Source: http://en.wikipedia.org/wiki/Workflow
What is Workflow?
• Sequential Workflow
– Looks like a flow chart
• 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
• 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
• 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
• 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
• For example
– Need to return inventory to stock when
customer cancel order
Activities with Compensation
Logic
Long-running workflow
Atomic Transaction
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
Get Item DB
Re-queue Item DB
De-queue Item DB
• 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
• adamcogan@ssw.com.au
• markliu@ssw.com.au
THANK
YOU!