Download presentation
Presentation is loading. Please wait.
1
Introduction to Windows Workflow Foundation
Silvano Coriani Developer Evangelist Microsoft
2
Agenda What is Windows Workflow Foundation?
Architecture & Core concepts Building Workflows Introduction to Activities Workflow Styles Workflow Authoring Tools Runtime services Workflow communications
3
Workflow Software Challenges
Real World Behavior Software Challenges Long Running and Stateful Workflows run for up to 30 days and must maintain state throughout “Orders are confirmed in 48 hours and shipped within 30 days” “Most suppliers confirm our orders but some forget and we need to followup” Flexible Control Flow Flexibility for people to override or skip steps in the workflow Transparency Rendering runtime state within a visualization of the workflow control flow “What is the status of this order and what is the next step?”
4
Why Workflow Technology?
Developer Productivity Workflows technology provides abstractions convenient to describe real world scenarios Workflow software challenges Workflows are long running and stateful Workflows require flexible control flow Workflows must provide transparency
5
Microsoft’s Workflow Strategy is …
to provide Windows Workflow Foundation as a part of the developer framework for Windows and enterprise applications that build on top of Windows Workflow Foundation for specific scenarios. A ISV developer building a line of business application chooses to use Windows Workflow Foundation within the business logic of their application. An enterprise customer uses BizTalk Server to provide system workflow across their existing line of business applications and trading partners to reduce their cycle-times and increase business visibility in a high-volume environment. For Example For Example
6
Windows Workflow Foundation
Deliver best-in-class workflow platform & tools for Microsoft products and partner/customer ecosystem Single workflow technology for Windows Available to all customers of Windows Available for use across a broad range of scenarios Redefining workflow Extensible framework & API to build workflow centric products One technology for human and system workflow Take workflow mainstream Incremental learning for mainstream .NET developer Fundamental part of the Office “12” value proposition Strong workflow partner & solution ecosystem
7
What is a workflow? A set of activities that coordinate people
and / or software... Example activities…. EscalateToManager CheckInventory …organized into some form of workflow. Like a flowchart…. Or a state diagram….
8
Workflow Scenario Spectrum
System Workflow Human Workflow Participants: people, roles Flow style: flexible, dynamic Data: unstructured, documents Participants: apps, services Flow style: prescriptive, protocols Data: structured, transactional Business to Business Supply Chain Mgmt… Information Worker Document Review… Line of Business Apps Quote to Cash, Sales Automation… CRM ERP IT Management New Hire Provisioning, Trouble Ticket,… .NET Developer Pageflow, Service Coordination… Windows Workflow Foundation
9
Windows Workflow Foundation
Visual Designer Key Concepts Workflows are a set of Activities A Workflow Workflows run within a Host Process: any application or server Developers can build their own Custom Activity Libraries An Activity Custom Activity Library Components Windows Workflow Foundation Base Activity Library: Out-of-box activities and base for custom activities Base Activity Library Runtime Engine: Workflow execution and state management Runtime Engine Runtime Services: Hosting flexibility and communication Runtime Services Visual Designer: Graphical and code-based construction Host Process
10
Workflow Basics A workflow is a class
Imports System.Workflow.Activities Public Class MyWorkflow Inherits SequentialWorkflow … End Class A workflow class may be defined in markup <?Mapping XmlNamespace="Activities" ClrNamespace="System.Workflow.Activities" Assembly="System.Workflow.Activities" ?> <SequentialWorkflow x:Class="MyWorkflow" xmlns="Activities" xmlns:x="Definition"> … </SequentialWorkflow>
11
Workflow Execution My Application Create instance Execute until idle
rt.StartWorkflow(typeof(WF1)); Invoke1 WF1 Instance 1 App calls StartWorkflow(…) Sequence 2 Instance Manager: Loads workflow type Creates instance Enqueues WF1 with Scheduler WF1 OnEvent1 Execute MyWF.dll Execute until idle 3 Scheduler dequeues WF1 and calls Executor (SequentialWorkflow base) which enqueues Sequence SequentialWorkflow Execute Base Activity Library Sequence Execute 4 Dequeue Sequence and call Executor which enqueues OnEvent1 Activity Save Dequeue OnEvent1 and call Executor which subscribes to event 5 Instance Manager Persist to disk Runtime Engine InstanceMgr calls Save() on WF1 (Activity base class) to serialize instance and gets back stream 6 Scheduler WF1 Sequence OnEvent1 Instance Mgr call Persistence service passing serialized stream - Persistence service saves to disk 7 Runtime Services WF1 Persistence
12
Activity Basics Activities are the building blocks of workflows
The unit of execution, re-use and composition Basic activities are steps within a workflow Composite activities contains other activities EG: Sequence Base Activity Library provides out-of-the-box activity set Partners and customers author custom activities EG: “ApproveOrder” Activities are classes: Properties and events are defined by the activity author and programmable from workflows Has methods that are coded by the activity author but invoked by the workflow runtime (EG: Execute) or designer Can be built into workflow assemblies or deployed as re-usable libraries
13
Activities: Optional Features
Companion Classes [Designer(typeof(MyDesigner))] [Validator(typeof(MyValidator))] [CodeGenerator(typeof(MyCodeGen))] [Serializer(typeof(MySerializer))] [ToolboxItem(typeof(MyToolboxItem))] Designer Validator Serializer Code Generator ToolboxItem Behaviors [SupportsTransaction] [SupportsExceptionHandlers] Transactions public class MyActivity: Activity { ... }
14
Activities: An Extensible Approach
Vertical-specific activities & workflows Best-practice IP & Knowledge Domain-Specific Workflow Packages Compliance RosettaNet CRM IT Mgmt Base Activity Library Custom Activity Libraries Compose activities Extend activity Author new activity Out-of-Box Activities OOB activities, workflow types, base types General-purpose Activity libraries define workflow constructs Create/Extend/ Compose activities App-specific building blocks First-class citizens Sequencing engine driven by activities (no fixed language)
15
Flexible Control Flow Sequential Workflow State Machine Workflow
structure prescribes processing order External events drive processing order Step1 State1 Event State2 Step2 Event Prescriptive, formal Automation scenarios Flowchart metaphor Reactive, event-driven Skip/re-work, exception handling Graph metaphor Rules-driven Activities Rule1 Step1 Rules + data state drive processing order Data Rule2 Step2 Data-driven Simple Conditions, complex Policies Constrained Activity Group
16
Spectrum of Workflow Authoring Tools
Line of Business Manager / End users Wizards Business Analyst Visio Like Script Developers or VARs Script Like Code Developers or ISVs Windows Workflow Foundation Designer Commonality between Tools: Support a common object model for describing Workflow information The object model needs to be exchangeable between tools
17
Take Workflow Mainstream: Design
Activity Designer Sequential Designer State Machine Designer Workflow Designers (À la ‘ASP.NET’ Designer) Create new workflows Visual (/code) authoring Seamlessly integrate .NET code with round-tripping Visual debugging Themes support Designer re-hosting Activity Designer (À la ‘UserControl’ Designer) Create new activities Visual (/code) authoring Inherit from base activities or start from scratch Black-box/Gray-box composition support Consistent and Familiar Experience for Workflow Development
18
Workflow Authoring Modes
Markup Only “Declarative” Markup and Code Code Only Application Generated C#/VB C#/VB App creates activity tree and serializes XAML XAML XML defines workflow structure logic and data flow XML defines workflow Code-beside defines extra logic Code creates workflow in constructor C#/VB XAML Workflow Compiler wfc.exe .NET assembly ctor defines workflow C#/VB Compiler
19
Workflow Enabled Office Take Workflow Mainstream: Office “12”
SharePoint: Start/participate, customize, and track workflows Workflows run inside SharePoint and are accessible across the Office System OutLook: Receive notifications and track tasks FrontPage: Create and customize workflows Workflow Enabled Office Word, PowerPoint, Excel, InfoPath: Start/participate in SharePoint workflow Take Workflow Mainstream: Office “12” Office “12” Workflow Vision Provide document centric workflow as an integrated part of the Office experience Empower information workers with common workflow solutions and activities out of the box Empower organizations to build sophisticated workflow using the full functionality of the broader platform
20
Runtime Engine And Services
My workflow Windows Workflow Foundation Base Activity Library Runtime Engine Provides intrinsic behaviors to activities Tracking Infrastructure State Management Workflow Execution Dynamic Update Should mention that there are a total of 5 services we provide. We may want to enumerate them all here. Need to mention some host samples. SharePoint would be a host for our technology. Biztalk in the future would be a host for our technology. A WinForm application and a Windows Service could be also considered a host. Runtime Services Hosting flexibility - pluggable implementations (with defaults) Persistence Communication Tracking … Host Process
21
Runtime Services The workflow runtime is lightweight
Depends on a set of services Only Threading is required Often you also want Transactions and Persistence Add services programmatically or using a config file What ships in System.Workflow.Runtime.Hosting? Abstract service definitions Concrete service implementations DefaultThreadingService (asynchronous) ManualThreadingService (synchronous; for ASP.NET scenarios) DefaultTransactionService SqlPersistenceService
22
Runtime Services Host Application App Domain Runtime Services SQL
TimerService manages timers – e.g. Delay activity. Services Out of Box Services are provided that support SQL Server 2000 & 2005 TimerService PersistenceService stores and retrieves instance state. SQL PersistenceService TrackingService TrackingService manages profiles and stores tracked information. The runtime uses default implementation of these services. But they can be replaced by your own implementations. Out-of-the-box we offer SQL as persistence store for Tracking, State Persistence, and Timer persistence. ThreadingService TransactionService Common resource services for managing threading and creating transactions
23
Out-of-Box Services ASPNetThreadingService
Synchronous threading service used for in-line execution; used by ASP module for web services DefaultThreadingService Used for asynchronous execution of workflows; uses default .Net thread pool DefaultWorkflowTransactionService Creates .NET transactions SharedConnectionWorkflowTrans-actionService Sql* services share connection to SqlServer InMemoryTimerService Stores timer information in-memory, i.e. for Delay activity SqlTimerService Stores timer information in SqlServer/MSDE; i.e. for Delay activity SqlStatePersistenceService Stores workflow instance state information in SqlServer/MSDE SqlTrackingService Stores tracking information in SqlServer/MSDE
24
Workflow State Management
Many workflows are long running A workflow instance is idle when it has no runnable work WF unloads-on-idle by default, but the host can take full control Loading/unloading is not a concern of the workflow developer or the application developer Persistence points are checkpoints Transactions Enable crash recovery Persistence occurs at: Closure of a transaction Closure of any activity marked [PersistOnClose] Closure of the workflow Custom services can participate in the transaction Even if there is no transaction modeled in the workflow The transaction is committed when a workflow persistence point is reached
25
Enabling Workflow Persistence
Persistence Support for Workflow Instances Create the SQL database with the SqlStatePersistence schema Create a Workflow Runtime Define Connection String Register StatePersistenceService with Runtime Register TimerService with Runtime Start the Workflow Loading and Unloading uses StatePersistenceService private void RunWorkflow() { WorkflowRuntime wr = new WorkflowRuntime(); string connectionstring = "Initial Catalog=Persistence;Data Source=localhost;Integrated Security=SSPI;"; wr.AddService(new SqlStatePersistenceService(connectionstring)); wr.AddService(new SqlTimerService(connectionstring)); wr.StartWorkflow(typeof(SimpleWorkflow)); } We need to mention that I’m using our OOB services. They could build their own. Make sure I mention it doesn’t have to be SQL DB.
26
Tracking Tracking Activities Service Workflow Instance
Track all state changes and data within the workflow Emit tracking info from code Dynamic changes Profile XML file that specifies what to track Includes and excludes, state changes, data context, types Object model to create Tracking Information Tracking Service Need to mention that tracking services can go against any back end system not only RDBMS. Imagine a tracking service that goes against the Event Log, Files, or Raise Events. Need to verify when Tracking actually happens, how synchronous is it? Write Store Activities Profile Workflow Instance Host Application Query
27
Tracking Architecture
Workflow Runtime Listener asks each services for their profile(s) Service only gets called based on what is specified in the profile(s) Multiple tracking services can be loaded per the application’s requirements Workflow Instance Profile SqlTrackingService Execution Listener FileTrackingService Profile SqlTrackingService Channel FileTrackingService Channel
28
Enabling Workflow Tracking
Tracking Support for Workflow Instances Define tracking profiles Create workflow runtime Define connection string Register one or more TrackingService’s with the WorkflowRuntime Start the workflow Query tracking database – instance and activity information private void RunWorkflow() { WorkflowRuntime wr = new WorkflowRuntime(); string connectionstring = "Initial Catalog=Tracking;Data Source=localhost;Integrated Security=SSPI;"; //Out of the Box Tracking Service wr.AddService(new SqlTrackingService(connectionstring)); wr.StartWorkflow(typeof(SimpleWorkflow)); } Need to mention that tracking services go beyond DB. They could be defined against the event logs, files, etc.
29
Workflow & Communications
The purpose of a workflow is often to coordinate work performed outside of its boundaries Many workflows are long-running programs Communication is an inherent need The communication may be local (intra-process) To and from your hosting application code The communication may be remote Web services Windows Communication Foundation (Indigo)
30
Communication Architecture
Local Application Remote Application Communication Services Proxy management Correlation Custom Host ASP.NET Local App Object Local App Object Web Service Local App Object Local App Object Local App Object Runtime Scheduling Workflow Runtime Workflow Instances WebServiceReceive WebServiceResponse InvokeWebService InvokeMethod EventSink Activities Model sending and receiving of data
31
Local Communication Architecture
.NET object managed by the runtime acts as a communication intermediary between the host and the workflow instances Raises events into the workflow Proxy for outbound method calls Four components: Local Communication Activities Contract Local Service EventArgs Application Workflow Method Event Workflow Runtime Output DataExchangeService Input
32
Local Communication Activities Model sending and receiving data
EventSink activity Model an event raised by a local object (Application Workflow) InvokeMethod activity Model the invocation of a method on a local object (Workflow Application) OrderManager WorkflowRuntime
33
Local Communication Contract Define pattern of communication
Write an interface that defines the contract for communication with the workflow Events for inbound data (to workflow) Methods for outbound data (from workflow) Mark as [DataExchangeService] [DataExchangeService] public interface IOrderManager { // Create a workflow instance to process the order event EventHandler<OrderEventArgs> OrderSubmitted; // The workflow instance will later call one of these methods void Approve(string orderId); void Reject(string orderId); }
34
Local Communication Service Implement class
Implement the interface you’ve defined Singleton (will be shared by all workflow instances) Register with the runtime public class OrderManager : IOrderManager { // Create a workflow instance to process the order public event EventHandler<OrderEventArgs> OrderSubmitted; // The workflow instance will later call one of these methods public void Approve(string orderId) { … } public void Reject(string orderId) { … } } WorkflowRuntime runtime = new WorkflowRuntime(); OrderManager orderManager = new OrderManager(); runtime.AddService(orderManager);
35
Local Communication Event Args Define event data
The runtime intercepts events raised by the registered local object, and delivers them to the right workflow instances Must derive from WorkflowMessageEventArgs and include the workflow instanceId Conceptually, the registered local object is addressing a workflow instance when it raises an event public class OrderEventArgs : WorkflowMessageEventArgs { public OrderEventArgs(Guid instanceId, string orderId) : base(instanceId) … }
36
Coordinating Services
Workflows are an excellent way to coordinate services Service interaction becomes: Declarative – modeled using activities in a workflow Transparent - to the outside world Visual – for designing, debugging, and monitoring Composable - Data can be flowed from activities/services Simplified - Workflows simplify message exchange patterns Flexible - Easily be modified and dynamically changed Services Workflow
37
Implementing Services using Workflow
Challenges developing services today Services are often used together as part of a business process, but are not explicitly associated Services often front-end, long-running business processes Workflows are an excellent way to implement service logic State management across multiple service interactions Services are explicitly associated in a workflow model Implementation can be transparent Enables runtime visibility into the state of the service Runtime behavior is configurable Tracking, persistence, etc. Services Workflow
38
Web Services Activities
InvokeWebService Like Visual Studio Add Web Reference Session-aware Can manipulate the proxy before the call For example, to set credentials Parameter binding WebServiceReceive, WebServiceResponse Model 1-way and 2-way requests to the workflow Define web service contract as an interface Generate default web service project plus artifacts with a single click in Visual Studio
39
Web Services Hosting WorkflowWebHostingModule WorkflowWebService
ASP.Net 2.0 IHttpModule Session-based request routing Not required to use this (replaceable) WorkflowWebService Default base class for published workflows Not a required base class for your web services Workflow Runtime Services ASPNetThreadingService Uses request thread to process workflow WebTimerService Persistent timer service
40
Web Services Build transparent, flexible, long-running web services
ASP.NET Build transparent, flexible, long-running web services Model all data entry and exit points Host the workflow runtime in ASP.NET WorkflowWebService WorkflowWebHostingModule Workflow Runtime Workflow Receive Response Invoke Runtime Services Session Threading Service Timers Timer Service Workflow State Persistence Service
41
Why Workflow & Services?
Services make workflow more accessible Workflows make services more composable Services Services Workflow While these two usage scenarios could absolutely be independent, they can also be used together. Imagine building a workflow that consumes several services, but it is actually exposed as a service itself so it can easily be accessed from another application – such as the User Interface. We integrate software by exchanging messages with services Two general usage scenarios: Consuming services within a workflow Accessing workflows as services Services make workflow more accessible Workflows make services more composable Secure, reliable, transactional services Unified API for communications Support for key WS-* protocols Transport selection TCP, HTTP, Named Pipes, P2P, MSMQ, Custom Multiple Message Exchange Patterns Request-Response, Duplex, One-Way Analogy – object-driven development vs. data-driven development UML – state machines Service implementation is opaque to client Service implementation is also opaque to implementer, runtime, IT pro, knowledge worker and my mom – Enter Workflow
42
Workflow & Communications Foundation
Declarative control flow Simplified programming model Process visualization Dynamic execution Configurable runtime behavior Secure, reliable, transactional services Unified API for communications Transport selection Multiple Message Exchange Patterns We integrate software by exchanging messages with services Two general usage scenarios: Consuming services within a workflow Accessing workflows as services Services make workflow more accessible Workflows make services more composable Secure, reliable, transactional services Unified API for communications Support for key WS-* protocols Transport selection TCP, HTTP, Named Pipes, P2P, MSMQ, Custom Multiple Message Exchange Patterns Request-Response, Duplex, One-Way Analogy – object-driven development vs. data-driven development UML – state machines Service implementation is opaque to client Service implementation is also opaque to implementer, runtime, IT pro, knowledge worker and my mom – Enter Workflow
43
WCF Activities Prototype activities designed for direct communications using WCF SendMessage ReceiveMessage SendReceive ReceiveSend Enables explicit asynchronous and sophisticated message exchange patterns Workflows wire up communications to services by configuring these activities Not provided with Windows Workflow Foundation
44
WCF with Local Services
Service Request WCF Service OrderManager Local Service Service Request WCF Service
45
Workflow and BizTalk Server
Premium BPM server Distinct server product Use in B2B, EAI, BPM scenarios Deployable solutions Manageability, Scale-out Design Tools Accelerators Business Activity Monitor And Admin Tools Workflow Orchestration Messaging Transformation Future version will migrate to Windows Workflow Foundation for orchestration Adapters Workflow framework Exposed via WinFX Broad set of scenarios Used to build solutions Enables manageability and scale-out in solutions Use for building workflow into apps or workflow-enabled servers Visual Studio Designer WinFX Windows Workflow Foundation
46
Summary A single workflow technology for Windows
Platform level workflow framework for use within Microsoft products & ISV applications Will be used by BizTalk Server, Office12, and Dynamics Available to all Windows customers Microsoft is redefining workflow Unified technology for System & Human workflow Multiple styles: sequential, rules-based, state machine Supports dynamic interaction Microsoft is taking workflow mainstream Consistent and familiar programming model for reaching mainstream application developer Available to millions of end-users through Office “12” Extensible platform for ISVs
47
© 2006 Microsoft Corporation. All rights reserved.
This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.