Windows Workflow Foundation


Published on

  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • Presentation: Windows Workflow Foundation Presenter: Usman Zafar Malik
  • Table of Contents What is Workflow? Workflow Types Fundamentals of Workflows Activities Custom Activities Types of Activities Workflow Framework How to Use Windows Workflow Foundation Windows Workflow and XAML Architecture Diagram Windows Workflow Runtime Hosting the Windows Workflow Runtime Runtime Services Creating Workflow-Enabled Services Modify Running Workflows WF in perspective of .NET 3.5 Summary Demos
  • Windows Workflow Foundation

    1. 1. Usman Zafar Malik
    2. 2. Agenda <ul><li>What is Workflow? </li></ul><ul><li>Workflow Types </li></ul><ul><li>Fundamentals of Workflows </li></ul><ul><li>Activities </li></ul><ul><li>Custom Activities </li></ul><ul><li>Types of Activities </li></ul><ul><li>Workflow Framework </li></ul><ul><li>How to Use Windows Workflow Foundation </li></ul><ul><li>Windows Workflow and XAML </li></ul><ul><li>Architecture Diagram </li></ul><ul><li>Windows Workflow Runtime </li></ul><ul><li>Hosting the Windows Workflow Runtime </li></ul><ul><li>Runtime Services </li></ul><ul><li>Creating Workflow-Enabled Services </li></ul><ul><li>Modify Running Workflows </li></ul><ul><li>WF in perspective of .NET 3.5 </li></ul><ul><li>Summary </li></ul><ul><li>Demos </li></ul>
    3. 3. What is Workflow? <ul><li>A workflow is the series of steps, decisions, and rules needed to complete a specific task. </li></ul><ul><li>Example </li></ul><ul><ul><li> Order food at the local pizza shop </li></ul></ul><ul><ul><li> Tell the cashier the type of pizza you want </li></ul></ul><ul><ul><li> The cashier passes this information to the cook </li></ul></ul><ul><ul><li> Who gathers ingredients and puts a pizza in the oven </li></ul></ul><ul><ul><li> The cook hands a finished pizza to the cashier </li></ul></ul><ul><ul><li> Who collects payment and completes the workflow by handing </li></ul></ul><ul><ul><li>over your pizza </li></ul></ul><ul><ul><li>The work flows , to the cashier, then to the cook, and then back again. </li></ul></ul><ul><li>* Programming Windows Workflow Foundation </li></ul><ul><li>Practical WF Techniques and Examples using XAML and C# </li></ul>
    4. 4. Workflow Types <ul><li>Three types of workflows </li></ul><ul><ul><li>Sequential Workflows </li></ul></ul><ul><ul><li>State Machine Workflows </li></ul></ul><ul><ul><li>Rules-Driven Workflows </li></ul></ul>
    5. 5. Workflow Types (contd) <ul><li>Sequential Workflow </li></ul><ul><ul><li>It progresses from one stage to next and cannot step back. Example: Flow Chart Based. </li></ul></ul><ul><li>State Machine Workflow </li></ul><ul><ul><li>It progresses from “State” to “State” and are more complex and can return to the previous point. </li></ul></ul><ul><li>Rules-Driven Workflow </li></ul><ul><ul><li>Implemented based on Sequential workflow. The rules dictate the progress of the workflow. </li></ul></ul>
    6. 6. Fundamentals of Workflows
    7. 7. Activities <ul><li>Activities are the building blocks of workflows. </li></ul><ul><li>All steps within a workflow are performed by executing an activity. </li></ul><ul><li>All activities in WF derive from an Activity base class </li></ul><ul><ul><li>Activities define some common operations like “Execute” and “Cancel” </li></ul></ul><ul><ul><li>Activities define some common properties like “Name” and “Parent”. </li></ul></ul><ul><ul><li>Activities define some common events like “Executing” and “Closed”. </li></ul></ul><ul><li>Primitive activities in the library provides a foundation to build upon. </li></ul><ul><li>Includes control flow operations like IfElseActivity, WhileActivity. </li></ul><ul><li>Also includes activities to wait for events, to invoke Web Services, to execute a rules engine etc </li></ul>
    8. 8. Activities (contd)
    9. 9. Custom Activities <ul><li>Allows developers to extend the functionality of base activity library by creating custom activities to solve problems in their specific domain. </li></ul><ul><li>All custom activities will also ultimately derive from the base Activity class </li></ul><ul><li>The workflow engine makes no special distinction between activities written by Microsoft and custom activities written by third parties </li></ul><ul><li>Example </li></ul><ul><ul><li>Pizza Order Case: “SendOrderToKitchen” or “NotifyCustomer” etc </li></ul></ul>
    10. 10. Types of Activities <ul><li>Two types of activities </li></ul><ul><ul><li>Sequence Activities </li></ul></ul><ul><ul><li>Event-Driven Activities </li></ul></ul>
    11. 11. Sequence Activities <ul><li>A sequential workflow completes one activity and moves to the next, executing a sequence of consecutive steps. </li></ul><ul><li>The “SequentialWorkflowActivity” class derives from the “SequenceActivity” class, which in turn derives from the CompositeActivity class. </li></ul><ul><li>The “CompositeActivity” class provides the logic for an activity to contain one or more child activities. </li></ul><ul><li>A sequential workflow will typically contain multiple children, and sequence activity provides the logic to execute child activities. </li></ul>
    12. 12. Sequence Activities (contd) <ul><li>The Sequence Activity iterates through its children in a forward-only direction, executing each child once and then moving to the next child. When the last child activity is complete, the sequence is finished. This doesn't mean a sequential activity cannot loop or branch, but it does mean execution always moves forward. </li></ul><ul><li>There is no mechanism available to jump back to an arbitrary activity in the workflow. </li></ul>
    13. 13. Sequence Activities (contd)
    14. 14. Event-Driven Activities <ul><li>A state machine workflow is an event-driven workflow. </li></ul><ul><li>The state machine workflow relies on external events to drive the workflow to completion. </li></ul><ul><li>What is a State Machine? Elaborate in the Diagram shown below </li></ul>
    15. 15. Event-Driven Activities (contd) <ul><li>A transition moves the state machine to the next state. A transition can only occur in response to an event. Transitions don't have to move the state machine to a new state—a transition could loop back to the same state </li></ul><ul><li>Each state can be activated after a predefined action has taken place; then, the engine executes the activities needed and stops after completion of the next state. There is no deterministic execution path between the steps because the Workflow does not execute in a chronological order </li></ul>
    16. 16. Workflow Framework <ul><li>WF is an extensible framework to deal with workflows in applications of any type. </li></ul><ul><li>It is a set of classes and design tools that help you create and develop workflows into your applications. Just as the System.Windows namespace helps you create windows applications, the System.Workflow namespace will help you create workflows </li></ul><ul><li>WF provides the base workflow classes for Sequential Workflows and State Machine Workflows </li></ul>
    17. 17. How to Use Windows Workflow Foundation <ul><li>Microsoft Visual Studio 2005 Extensions for Windows Workflow. </li></ul><ul><li>Where as in Microsoft Visual Studio 2008 it is built in. </li></ul>
    18. 18. Windows Workflow and XAML <ul><li>eXtensible Application Markup Language (XAML, Pronounced as Zammel) </li></ul><ul><li>XAML file are the valid XML files. </li></ul><ul><li>It brings a declarative programming model to Windows Workflow. </li></ul><ul><li>Designer can read/write XAML. </li></ul><ul><li>XAML is not a technology specific to Windows Workflow, it also present in WPF, which declaratively constructs a rich user interface consisting of not only buttons and labels, but also animation storyboards etc </li></ul>
    19. 19. Architecture Diagram
    20. 20. Architecture Diagram (contd) <ul><li>Top Layer </li></ul><ul><ul><li>At the top of the model is the location where developers build the code to run a workflow. This layer provides the out-the-box Activities, the model for the construction of custom Activities, and the engine to build rules. </li></ul></ul><ul><li>Middle Layer </li></ul><ul><ul><li>The Runtime layer ensures the execution aspects of the workflow and contains the mission-critical services required: for example, the state management and persistence service, the rules service that provides policy execution functionality, the scheduler service, and the tracking service. </li></ul></ul><ul><li>Bottom Layer </li></ul><ul><ul><li>The Hosting layer is the connecting link between the Workflow Foundation and the outside world and provides a package of services (Persistence, Timer, Tracking, Communication) needed to guarantee the control and management of the workflow. </li></ul></ul>
    21. 21. Windows Workflow Runtime <ul><li>View the workflow activities as instructions, or opcodes, for a workflow processor to execute. In Windows Workflow, the processor is in the WF runtime. </li></ul><ul><li>Workflow runtime provides common facilities for running and managing the workflows and can be hosted in any CLR application domain, be it a Windows Service, a Console, GUI or Web Application. </li></ul>
    22. 22. Hosting the Windows Workflow Runtime <ul><li>WF lives inside a handful of assemblies like System.Windows.Workflow.Runtime </li></ul><ul><li>Like ASP.Net Runtime, the WF needs a host process to load, initialize and start its runtime before anything interesting can happen. </li></ul><ul><li>WF will be useful in a variety of different hosts. We can host WF in a smart client application, a console application, or a Windows service, for instance. </li></ul>
    23. 23. Hosting the Windows Workflow Runtime (contd) <ul><li>Example </li></ul><ul><ul><li> Create Instance of WorkflowRuntime </li></ul></ul><ul><ul><li> Calling Start() method of Runtime </li></ul></ul><ul><ul><li> Create the Worflow Instance </li></ul></ul><ul><ul><li> Executing the Workflow Instance Start( ) method </li></ul></ul><ul><ul><li> Worflow Completed then the Workflow Runtime fire Workflow Completed Event. </li></ul></ul>
    24. 24. Hosting the Windows Workflow Runtime (contd)
    25. 25. Runtime Services <ul><li>WF assemblies provide important services to the workflow runtime. </li></ul><ul><li>AddService allows us to make one or more services available to the runtime </li></ul><ul><li>There are different types of Runtime Services are available </li></ul><ul><ul><li>Scheduling Service </li></ul></ul><ul><ul><li>Transaction Service </li></ul></ul><ul><ul><li>Persistence Service </li></ul></ul><ul><ul><li>Tracking Service </li></ul></ul>
    26. 26. Scheduling Service <ul><li>A scheduling service controls threads the runtime needs to execute workflows. </li></ul><ul><li>The threads are separate from the host application because the workflows do not block any application thread and executes asynchronously. </li></ul><ul><li>We can control the maximum number of workflows that runs simultaneously. </li></ul><ul><li>Two types of scheduling services </li></ul><ul><ul><li>DefaultWorkflowSchedulerService  Asynchronously </li></ul></ul><ul><ul><li>ManualWorkflowSchedulerService  Synchronously </li></ul></ul>
    27. 27. Scheduling Service (contd) <ul><li>The “ DefaultWorkflowSchedulerService ” creates new threads to execute workflows. </li></ul><ul><li>The “ ManualWorkflowSchedulerService ” is available when the host application is willing to donate threads to the workflow runtime. </li></ul><ul><li>Denoating a thread to the Runtime is useful technique in server‑side applications, like ASP.NET web applications and web services. The ManualWorkflowSchedulerService forces the workflow instance to be run on the host instances thread so the host application is blocked until the workflow instance completes or becomes idle. This method is recommended when it is important to conserve the .Net thread pool, specifically when a workflow is instantiated by ASP.Net. </li></ul>
    28. 28. Scheduling Service (contd)
    29. 29. Transaction Service <ul><li>The purpose of the transaction service it to enable custom logic regarding the commitments of work batches (also known as Persistent Points) </li></ul><ul><ul><li>DefaultWorkflowCommitWorkBatchService. </li></ul></ul><ul><ul><li>SharedConnectionWorkflowCommitWorkBatchService. </li></ul></ul><ul><li>Both “DefaultWorkflowTransactionService” and “SharedConnectionWorkflowTransactionService” inherit from “ WorkflowTransactionService ” which is the base transaction service class </li></ul>
    30. 30. Persistence Service <ul><li>This service saves the current state of the workflow. </li></ul><ul><li>In workflows if state is not saved then user will lost the data and workflows would be terminated while in process. </li></ul><ul><li>It is desirable to unload the process from the memory so that the resources are not held. </li></ul><ul><li>It restarts the process from the same state getting from the persistence store from where it is saved. </li></ul><ul><ul><li>Example: </li></ul></ul><ul><ul><ul><li>user approval process is accomplished and workflow restarts from the persistent state. </li></ul></ul></ul>
    31. 31. Persistence Service (contd) <ul><li>It is useful in those scenarios where the activity may take long time getting a response, like waiting for an approval from a user. </li></ul><ul><li>Default Runtime Service supplied with WF is “SQLStatePersistenceService”. </li></ul><ul><li>The state is store in the SQL DB. </li></ul><ul><li>If you are going to use this service you need to create the database and run the scripts mentioned below. </li></ul><ul><ul><li>SQLPersistenceService_Schema.sql </li></ul></ul><ul><ul><li>SQLPersistenceService_Logic.sql </li></ul></ul><ul><li>It can be available at the following path “<windows>Microsoft.NetFrameworkv3.0Windows Workflow FoundationSQLEN” </li></ul>
    32. 32. Persistence Service (contd) <ul><li>The persistence service can be added to the runtime instance in two ways. </li></ul><ul><ul><li>Programmatically using code </li></ul></ul><ul><ul><ul><li>WorkflowRuntime workflowRuntime = new WorkflowRuntime(); </li></ul></ul></ul><ul><ul><ul><li>SqlStatePersistenceService stateservice = new SqlStatePersistenceService(&quot;Data Source=localhost;Initial Catalog=WFState;Integrated Security=True&quot;); </li></ul></ul></ul><ul><ul><ul><li>workflowRuntime.AddService(stateservice); </li></ul></ul></ul><ul><ul><li>Using a section in App.config </li></ul></ul><ul><li> <WorkflowRuntime Name=&quot;SampleApplication&quot; UnloadOnIdle=&quot;true&quot;> </li></ul><ul><li> <Services> </li></ul><ul><li><add type=&quot;System.Workflow.Runtime.Hosting.SqlStatePersistenceService, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&quot; ConnectionString=&quot;Data Source=localhost;Initial Catalog=WFState;Integrated Security=True;&quot; /> </li></ul><ul><li> </Services> </li></ul><ul><li></WorkflowRuntime> </li></ul>
    33. 33. Persistence Service (contd) <ul><li>There are different attributes that can be defined are </li></ul><ul><ul><li>OwnershipTimeoutSeconds  Loading instance for the </li></ul></ul><ul><ul><li>specified period of time </li></ul></ul><ul><ul><li>UnloadOnIdle  True means persist the workflow and </li></ul></ul><ul><ul><li>unload it from memory </li></ul></ul><ul><ul><li>LoadIntervalSconds  How frequently check for </li></ul></ul><ul><ul><li>expired timers in workflow </li></ul></ul><ul><ul><li>EnableRetries  True tells the service to retry persisting </li></ul></ul><ul><ul><li>a workflow if it fails </li></ul></ul>
    34. 34. Persistence Service (contd)
    35. 35. Tracking Service <ul><li>This service is used to track the activity in the running workflows. </li></ul><ul><li>A tracking service uses a tracking profile to filter the information it receives about a workflow </li></ul><ul><li>The WF runtime can send information about workflow events, activity state changes, rule evaluations, and our own custom instrumentation data. </li></ul><ul><li>The tracking service decides what it will do with the data it receives. </li></ul><ul><li>The service could write tracking data to a log file, or save the data in a database. </li></ul><ul><li>The tracking service can participate in transactions with the workflow runtime to ensure the information it records is consistent and durable. </li></ul><ul><li>Provides things like when the workflow begins execution, when it ends, when each activity within the workflow is entered and exited. </li></ul>
    36. 36. Tracking Service (contd)
    37. 37. Tracking Service (contd) <ul><li>The runtime sends three types of events to the tracking service. </li></ul><ul><ul><li>Workflow events </li></ul></ul><ul><ul><li>Activity events </li></ul></ul><ul><ul><li>User events </li></ul></ul>
    38. 38. Tracking Service (contd) <ul><li>Workflow Events </li></ul><ul><ul><li>Workflow events describe the life cycle of the workflow instance. </li></ul></ul><ul><ul><ul><li>Created , Completed , Idle , Suspended , Resumed , Persisted , Unloaded , Loaded , Exception , Terminated , Aborted , Changed , and Started. </li></ul></ul></ul><ul><li>Activity Events </li></ul><ul><ul><li>Activity events describe the life cycle of an individual activity instance. </li></ul></ul><ul><ul><ul><li>Activity-execution status events include Executing , Closed , Compensating , Faulting , and Canceling. </li></ul></ul></ul><ul><li>User Tracking Events </li></ul><ul><ul><li>When creating the business logic for an activity, the activity author might want to track some business- or workflow-specific data. This can be achieved by calling any of the overloaded Activity.TrackData methods. The data tracked in this manner is sent to the tracking service as a User Tracking Event </li></ul></ul>
    39. 39. Tracking Service (contd) <ul><li>Tracking information sounds like a useful feature for system administrators who want to analyze resource usage, but there are also tremendous business scenarios for tracking information, like record tracking number of open/closed invoices etc. </li></ul><ul><li>Default tracking service provided by WF is “SQLTrackingService”. </li></ul><ul><li>It requires a SQL database. </li></ul><ul><li>If you are going to use this you need to create a database in SQL Server and run the specified scripts mentioned below </li></ul><ul><ul><li>Tracking_Schema.sql </li></ul></ul><ul><ul><li>Tracking_Logic.sql </li></ul></ul><ul><li>It can be available at the following path “<windows>Microsoft.NetFrameworkv3.0Windows Workflow FoundationSQLEN” </li></ul>
    40. 40. Tracking Service (contd)
    41. 41. Creating Workflow-Enabled Services <ul><li>In .NET 3.5 you can use WF and WCF together to create workflow-enabled services. </li></ul><ul><li>This combination depends on two new WF activities. </li></ul><ul><li>Send: </li></ul><ul><ul><li>Sends a request via WCF, then optionally waits for a response. </li></ul></ul><ul><ul><li>A developer specifies the operation that should be invoked and the endpoint that at which that operation can be found. </li></ul></ul><ul><li>Receive: </li></ul><ul><ul><li>Receives an incoming request via WCF, then sends a response. </li></ul></ul><ul><ul><li>The developer specifies just the operation that accept this incoming request. </li></ul></ul><ul><ul><li>Receive is a composite activity. </li></ul></ul><ul><ul><li>This activity can be used to cause a running workflow to wait for an incoming request, or a workflow that begins with a Receive activity can have a new instance created when a request arrives. </li></ul></ul>
    42. 42. Modify Running Workflows <ul><li>Human workflow requires the ability to make changes on the fly. </li></ul><ul><li>To allow this , WF include “ dynamic update ”. </li></ul><ul><li>Using this a running instance of any workflow can be modified within safe, well-defined boundaries specified by its creator, then potentially save as a new workflow. </li></ul><ul><li>A new activity can be inserted into the workflow. Or a rule condition changed for an IfElse or CAG activity. </li></ul>
    43. 43. WF in perspective of .NET 3.5 <ul><li>Basically a Model Driven Service Oriented Application. </li></ul><ul><li>Model Driven means, creating a process model using workflows as the medium for creating those models </li></ul><ul><li>Service Oriented means, you are exposing all the components of your application as service which are talking to each other using messages and services as the underline layer. </li></ul>
    44. 44. Summary <ul><li>Windows Workflow allows you to organize a set of activities into a workflow. </li></ul><ul><li>Workflows can be sequential or state machines. </li></ul><ul><li>You can create your own custom activities. </li></ul><ul><li>Workflows can be hosted in a variety of host applications </li></ul><ul><li>The Architecture of the Window Workflow Foundation. </li></ul><ul><li>Four types of Runtime services provided to workflows. </li></ul><ul><li>Workflow can make the application faster to build, quicker to change and easier to customize. </li></ul>
    45. 45. Thanks !