Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

Windows WorkFlow Foundation Presentation

Published in: Education, Technology
  • Be the first to comment


  1. 1. Windows Workflow Foundation Ch. Vishwa Mohan Freelance Software Consultant & Corporate Trainer
  2. 2. Table of Contents <ul><li>Introduction to Workflow Foundation </li></ul><ul><li>Workflow Activities </li></ul><ul><li>Workflows & Workflow Runtime </li></ul><ul><li>Building Sequential Workflows </li></ul><ul><li>Communication with the Host </li></ul><ul><li>Custom Activities </li></ul><ul><li>State Machine Workflows </li></ul><ul><li>Using Transactions </li></ul><ul><li>Web Services and Workflows </li></ul><ul><li>WCF Services and Workflows </li></ul><ul><li>Policies and Rule Sets </li></ul><ul><li>Updating Workflows Dynamically </li></ul><ul><li>Windows Workflow Foundation Services </li></ul><ul><li>Embedding the Workflow Designer </li></ul>
  3. 3. Introduction to Workflow Foundation
  4. 4. WWF Overview <ul><li>Windows Workflow Foundation (WWF) is the programming model, engine, and tools for quickly building workflow-enabled applications on Windows. </li></ul><ul><ul><li>Workflow provides a model where you can define and execute processes using a set of building blocks called activities . </li></ul></ul><ul><li>Some of the scenarios of Windows Workflow Foundation includes: </li></ul><ul><ul><li>Enabling work-flow within the line of business applications. </li></ul></ul><ul><ul><li>User-interface page flows. </li></ul></ul><ul><ul><li>Document-centric workflow. </li></ul></ul><ul><ul><li>Human workflows. </li></ul></ul><ul><ul><li>Composite workflows for Service-oriented applications. </li></ul></ul><ul><ul><li>Business rule-driven workflows. </li></ul></ul><ul><ul><li>Workflow for systems management. </li></ul></ul><ul><li>WWF provides a consistent and familiar development experience. </li></ul><ul><ul><li>The WWF API provides fully support for VB.NET and C#. </li></ul></ul><ul><ul><li>A specialized workflow compiler and debugger to debug within workflow. </li></ul></ul><ul><ul><li>A graphical workflow designer. </li></ul></ul><ul><ul><li>Facility to develop your workflow completely in code or in markup. </li></ul></ul><ul><li>Windows Workflow Foundation is a framework , not a language . It is cable to correctly handle persistence and compensation . </li></ul>
  5. 5. Workflow Overview <ul><li>A workflow is a set of elemental units called activities that are stored as a model that describes real-world processes. </li></ul><ul><ul><li>Workflows provides a way of describing the order of execution and dependent relationships between pieces of short-or long running work. </li></ul></ul><ul><ul><li>Here activities might be executed by people or by system functions. </li></ul></ul><ul><li>Every running workflow instance is created and maintained by an in-process runtime engine referred to as the Workflow Runtime Engine . </li></ul><ul><ul><li>There can be several workflow runtime engines within an application domain . </li></ul></ul><ul><ul><li>Also each instance of the runtime engine can support multiple workflow instances running concurrently. ( Here workflow runtime deals scheduling these instances ). </li></ul></ul><ul><li>When a workflow model is compiled, it can be executed inside any windows process includes: ( Because a workflow hosted in a process ). </li></ul><ul><ul><li>Console application. </li></ul></ul><ul><ul><li>Windows Forms based applications. </li></ul></ul><ul><ul><li>Windows Services. </li></ul></ul><ul><ul><li>ASP.NET Web Sites </li></ul></ul><ul><ul><li>ASP.NET Web Services. </li></ul></ul><ul><li>A workflow can easily communicate with its host application. </li></ul>
  6. 6. Host Process Windows Workflow Foundation Runtime Engine A Workflow An Activity Runtime Services Base Activity Library Custom Activity Library Visual Designer WWF Architecture <ul><li>Key Concepts: </li></ul><ul><ul><li>Workflows are set of activities . </li></ul></ul><ul><ul><li>Workflows run within a HostProcess . </li></ul></ul><ul><ul><li>Developers can build their own custom activity libraries . </li></ul></ul><ul><li>Components: </li></ul><ul><ul><li>Base Activity Library : Out-of-box activities and base for custom activities. </li></ul></ul><ul><ul><li>Runtime Engine : Workflow execution and State management </li></ul></ul><ul><ul><li>Runtime Services : Hosting flexibility and communication. </li></ul></ul><ul><ul><li>Visual Designer : Graphical and code based construction. </li></ul></ul>
  7. 7. What is an Activity ? <ul><li>Activities are the elemental unit of a workflow. </li></ul><ul><ul><li>An activity can perform a single action ( Eg: Writing a value to DB or sending an email ) or it can be a composite activity and consists of set of activities. </li></ul></ul><ul><li>Activities have two types of behavior: </li></ul><ul><ul><li>Runtime : It specifies the actions upon execution. </li></ul></ul><ul><ul><li>Design Time : It controls the appearance of the activity and its interaction while being displayed within the designer. </li></ul></ul><ul><li>Activities are executed according to given flow path . When all the activities are finished running, the working flow instance is completed its execution. </li></ul><ul><li>WWF framework consists a library of in-built activities also provides the mechanism for you to create your own activities; so it enables extensibility & reusability between workflows. Some of the framework in-built activities are: </li></ul><ul><ul><li>CallExternalMethodActivity </li></ul></ul><ul><ul><li>IfElseActivity, </li></ul></ul><ul><ul><li>IfElseBranchActivity </li></ul></ul><ul><ul><li>CodeActivity </li></ul></ul><ul><ul><li>FaultHandlersActivity, etc…, </li></ul></ul>
  8. 8. Workflow Rules & Conditions <ul><li>WWF can implement business logic as either rule or conditions . Conditions are used by one of the following activities to control activity execution. </li></ul><ul><ul><li>IfElseBranchActivity </li></ul></ul><ul><ul><li>ConditionedActivityGroup </li></ul></ul><ul><ul><li>WhileActivity </li></ul></ul><ul><ul><li>ReplicatorActivity </li></ul></ul><ul><li>Here conditions are expressed as declarative or defined in code . </li></ul><ul><ul><li>Declarative conditions are created as code DOM statements in the “ .rules” file. </li></ul></ul><ul><ul><li>Code-based conditions reference a method in the workflow’s code file that returns its result through Result property. </li></ul></ul><ul><li>Rules , like conditions , are expressed as code DOM statements, and are collected in the rules XML file. </li></ul><ul><ul><li>Here Rules include a condition statement and collection of actions which are performed based on the Result of the conditions. </li></ul></ul><ul><ul><li>Rules are collected into rule sets , which support both simple sequential execution of rules , and sophisticated forward-chaining of rules . </li></ul></ul><ul><li>Rule sets are executed by the PolicyActivity activity. </li></ul>
  9. 9. Fault Handling <ul><li>Exceptions that occur in activities are handled asynchronously by workflow runtime engine in a process called fault handling . </li></ul><ul><ul><li>Exceptions are scheduled in a queue to be handled later. If the exception type matches the one that is handled by a particular FaultHandlerActivity activity, that activity will handle the exception. </li></ul></ul><ul><ul><li>All the unhandled exceptions is bubbled up through parent activities until it ultimately causes the termination of workflow instance. </li></ul></ul>
  10. 10. Building Host to Run Workflows <ul><li>The WWF runtime engine is responsible for creating and maintaining running workflow instances. </li></ul><ul><ul><li>The runtime engine will be executed inside a host process . </li></ul></ul><ul><ul><li>The default mechanism for initializing WWF is to use the WorkflowRuntime class. </li></ul></ul><ul><ul><li>WorkflowRuntime wfRuntime = new WorkflowRuntime( ); </li></ul></ul><ul><ul><li>Once runtime instance is created you can subscribe for events those are raised by runtime engine also can configure any services used by runtime engine. </li></ul></ul><ul><ul><li>wfRuntime. WorkflowCompleted += OnWorkflowCompleted; </li></ul></ul><ul><ul><li>wfRuntime. WorkflowTerminated += OnWorkflowTerminated; </li></ul></ul><ul><ul><li>//Now add the services used by runtime. </li></ul></ul><ul><ul><li>wfRuntime. AddService (new SqlTrackingService(conn)): </li></ul></ul><ul><ul><li>Finally, create and start workflow instance. </li></ul></ul><ul><ul><li>WorkflowInstance instance = wfRuntime. CreateWorkflow (typeof(MyWorkflow)); </li></ul></ul><ul><ul><li>instance. Start() ; </li></ul></ul><ul><ul><li>To remove the service from runtime you can use RemoveSerice() method. Make sure runtime service is stopped ( i.e., not executing ). runtime. RemoveService (SqlTrackingService); </li></ul></ul>
  11. 11. Creating Workflow By Code <ul><li>To create a Workflow programmatically as follows: </li></ul><ul><ul><li>Create a console application in Visual Studio. </li></ul></ul><ul><ul><li>Add the following libraries to references of your project. </li></ul></ul><ul><ul><ul><li>System.Workflow.Activities </li></ul></ul></ul><ul><ul><ul><li>System.Workflow.ComponentModel </li></ul></ul></ul><ul><ul><ul><li>System.Workflow.Runtime </li></ul></ul></ul><ul><ul><li>Add a class file to your project and name the file as HelloWorld.cs . Now name the class name as HelloWorld and derived it from SequentialWorkflowActivity . </li></ul></ul><ul><ul><li>class HelloWorld : SequentialWorkflowActivity { } </li></ul></ul><ul><ul><li>In this class, declare a private variable of type CodeActivity . </li></ul></ul><ul><ul><li>private CodeActivity helloWorldActivity; </li></ul></ul><ul><ul><li>Now define a public constructor in this class and initialize CodeActivity instance in this constructor also associate code handler and add it to workflow. </li></ul></ul><ul><ul><li>this.helloWorldActivity = new System.Workflow.Activities. CodeActivity (); </li></ul></ul><ul><ul><li>this.helloWorldActivity. Name = &quot;HelloWorldActivity&quot;; </li></ul></ul><ul><ul><li>this.helloWorldActivity. ExecuteCode += new EventHandler(this. My HelloWorld); </li></ul></ul><ul><ul><li>Finally implement the MyHelloWorld event handler in your class: </li></ul></ul><ul><ul><li>private void My HelloWorld(object sender, EventArgs e) { } </li></ul></ul><ul><li>The complete code inside your workflow class Constructor is : </li></ul><ul><li>this. CanModifyActivities = true ; </li></ul><ul><li>this. Name = &quot;MyHelloWorldWorkflow&quot;; </li></ul><ul><li>this.helloWorldActivity = new System.Workflow.Activities. CodeActivity (); </li></ul><ul><li>this.helloWorldActivity. Name = &quot;HelloWorldActivity&quot;; </li></ul><ul><li>this.helloWorldActivity. ExecuteCode += ne w EventHandler(this.HelloWorld); </li></ul><ul><li>this.Activities. Add (this. helloWorldActivity ); </li></ul><ul><li>this. CanModifyActivities = false ; </li></ul>
  12. 12. Creating Workflow By Code <ul><li>The next step in creating and executing workflow is load your workflow by workflow runtime and execute it. </li></ul><ul><ul><li>In your project Program.cs file, within the main function create instance of WorkflowRuntime and create workflow instance as follow: </li></ul></ul><ul><ul><li>using ( WorkflowRuntime workflowRuntime = new WorkflowRuntime () ) { </li></ul></ul><ul><ul><li> AutoResetEvent waitHandle = new AutoResetEvent ( false ); </li></ul></ul><ul><ul><li>workflowRuntime. WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); }; </li></ul></ul><ul><ul><li> WorkflowInstance instance = workflowRuntime. CreateWorkflow (typeof(HelloWorldApp.HelloWorld)); </li></ul></ul><ul><ul><li> instance. Start (); </li></ul></ul><ul><ul><li> waitHandle.WaitOne(); </li></ul></ul><ul><ul><li> } </li></ul></ul>
  13. 13. Creating Workflow By Markup <ul><li>In addition to programmatically developing workflow, WWF also allows declarative way to create workflows by using XAML . </li></ul><ul><ul><li>These markup files can be compiled into a workflow type and loaded directly into the workflow runtime engine at runtime. </li></ul></ul><ul><ul><li>In addition they can also be compiled into a workflow type with code-behind files. </li></ul></ul><ul><ul><li>You can also use rules & rule conditions in markup. </li></ul></ul><ul><li>With the help of this markup language, in addition to creating workflows, you can also persist workflows by using WorkflowPersistanceService . </li></ul><ul><ul><li>When programmatic workflows are serialized with the WorkflowMarkupSerializer , they become workflow markup. </li></ul></ul>
  14. 14. Creating Workflow By Markup <ul><li>The basic structure of the workflow markup contains the root node , followed by the child activities in that workflow as nested sub elements. </li></ul><ul><ul><li>Here root node represents the type of workflow (Eg: Sequential, State Machine). </li></ul></ul><ul><ul><li>Each element in the workflow is represented as nodes of either composite activities or the workflow itself. </li></ul></ul><ul><ul><li>Each element in a workflow markup file corresponds to a workflow component. </li></ul></ul><ul><ul><li>XAML also provides the ability to insert procedural code within a workflow markup using the x:Code directive element. ( Code must be in CDATA section). </li></ul></ul><ul><li>If you use custom activities in your workflow markup code, then you need to reference the custom activity assembly in markup code as follows: </li></ul><ul><li>< SequentialWorkflowActivity x: Class =&quot;XAMLWorkflow.Workflow1&quot; x: Name =&quot;Workflow1&quot; </li></ul><ul><li>xmlns:ns0=&quot;Assembly=CustomActivityAssembly”> </li></ul><ul><li><ns0: CustomActivity x: Name =&quot;CustomActivity1&quot;/> </li></ul><ul><li></ SequentialWorkflowActivity > </li></ul><ul><li>To start workflow instance from markup file create XmlReader object contain markup file and pass it to CreateWorkflow() method of WorkflowRuntime . Finally call Start() method on WorkflowInstance object. </li></ul><ul><li>The IfElseActivity is represented in markup by the <IfElseActivity> element. </li></ul><ul><li>Example of code in markup file: </li></ul><ul><li>< CodeActivity x:Name=&quot;codeActivity1“ ExecuteCode=“MyMethod&quot;> </li></ul><ul><li><x:Code><![ CDATA [ </li></ul><ul><li>void MyMethod(object sender, EventArgs e) { } </li></ul><ul><li>]]></x:Code> </li></ul><ul><li></ CodeActivity > </li></ul>
  15. 15. Workflow Activities
  16. 16. Introduction to Activities <ul><li>Everything in a workflow is an activity . In WWF the activity is just a class that ultimately derived from the Activity class. </li></ul><ul><ul><li>Activity class defines a number of overridable methods (Eg: Cancel , Dispose, HandleFault, Execute ) and the most important of these methods is the Execute() . </li></ul></ul><ul><ul><li>override ActivityExecutionStatus Execute ( ActivityExecutionContext context ) { </li></ul></ul><ul><ul><li>return ActivityExecutionStatus.Closed ; </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><ul><li>When the runtime schedules the activity for execution, the Execute() method is ultimately called. ( Here you can write your custom code ). </li></ul></ul><ul><ul><li>The Execute() method return type is ActivityExeuctionStatus ( AES ). This enumeration values represents the status of activity instance within workflow instance. The possible values of ActivityExecutionStatus enumeration are: </li></ul></ul><ul><ul><ul><li>Initializing </li></ul></ul></ul><ul><ul><ul><li>Executing </li></ul></ul></ul><ul><ul><ul><li>Canceling </li></ul></ul></ul><ul><ul><ul><li>Closed </li></ul></ul></ul><ul><ul><ul><li>Compensating </li></ul></ul></ul><ul><ul><ul><li>Faulting </li></ul></ul></ul><ul><li>These values used by runtime to determine whether the activity has completed successfully, is still processing or one of the other possible states. </li></ul>
  17. 17. Activities Types <ul><li>There are two main types of Activities: </li></ul><ul><ul><li>Simple Activities : Activities those are derived from Activity class can be thought of as callable functions ( i.e., Execute , Cancel, etc.,) from the workflow. </li></ul></ul><ul><ul><li>Composite Activities : Activities that are derived from CompositeActivity class. These activities are container for other activities. These activities design time behavior is considerable different from Simple activities. ( Eg: ParallelActivity, IfElseActivity, ListenActivity ). </li></ul></ul><ul><li>Like workflow, an activity can be sequential or it can be event-driven . </li></ul>
  18. 18. Predefined Activities <ul><li>The WWF framework provides several predefined activities. These activities provides functionality for control flow, conditions, event handling, state management and communication with application and services. </li></ul><ul><ul><li>All these activities are defined in System.Workflow.Activities namespace. </li></ul></ul><ul><ul><li>The naming conversions for activities is to append Activity to activity name. </li></ul></ul><ul><li>The below is a list of WWF defined in built activities listed alphabetical order: </li></ul><ul><ul><li>CallExternalMethodActivity </li></ul></ul><ul><ul><li>CancellationHandlerActivity </li></ul></ul><ul><ul><li>CodeActivity </li></ul></ul><ul><ul><li>CompensatableSequenceActivity </li></ul></ul><ul><ul><li>CompensatableTransactionScopeActivity </li></ul></ul><ul><ul><li>CompensateActivity </li></ul></ul><ul><ul><li>CompensationHandlerActivity </li></ul></ul><ul><ul><li>ConditionedActivityGroup </li></ul></ul><ul><ul><li>DelayActivity </li></ul></ul>
  19. 19. Predefined Activities <ul><li>The below is a list of WWF defined in built activities listed alphabetical order: </li></ul><ul><ul><li>EventDrivenActivity </li></ul></ul><ul><ul><li>EventHandlersActivity </li></ul></ul><ul><ul><li>EventHandlingScopeActivity </li></ul></ul><ul><ul><li>FaultHandlerActivity </li></ul></ul><ul><ul><li>FaultHandlersActivity </li></ul></ul><ul><ul><li>HandleExternalEventActivity </li></ul></ul><ul><ul><li>IfElseActivity, </li></ul></ul><ul><ul><li>IfElseBrachActivity </li></ul></ul><ul><ul><li>InvokeWebServiceActivity </li></ul></ul><ul><ul><li>InvokeWorkflowActivity </li></ul></ul><ul><ul><li>ListenActivity </li></ul></ul><ul><ul><li>ParallelActivity </li></ul></ul><ul><ul><li>PolicyActivity </li></ul></ul><ul><ul><li>ReplicatorActivity </li></ul></ul>
  20. 20. Predefined Activities <ul><li>The below is a list of WWF defined in built activities listed alphabetical order: </li></ul><ul><ul><li>SequenceActivity </li></ul></ul><ul><ul><li>SetStateActivity </li></ul></ul><ul><ul><li>StateActivity </li></ul></ul><ul><ul><li>StateFinalizationActivity </li></ul></ul><ul><ul><li>StateInitializationActivity </li></ul></ul><ul><ul><li>SuspendActivity </li></ul></ul><ul><ul><li>SynchronizationScopeActivity </li></ul></ul><ul><ul><li>TerminateActivity </li></ul></ul><ul><ul><li>ThrowActivity </li></ul></ul><ul><ul><li>TransactionScopeActivity </li></ul></ul><ul><ul><li>WebServiceFaultActivity </li></ul></ul><ul><ul><li>WebServiceInputActivity </li></ul></ul><ul><ul><li>WebServiceOutputActivity </li></ul></ul><ul><ul><li>WhileActivity </li></ul></ul>
  21. 21. Activity Execution Model <ul><li>An activity may go through six different states it its lifetime: </li></ul><ul><li>An activity goes to initialized state when the Workflow runtime calls the activities Initialize() method. AEC created here. </li></ul><ul><li>Next runtime calls the Exeucte() method of activity. Here your activity enters into Executing state. Primary functionality performed here at this stage. It can return any one of the values of AES enumerator. </li></ul><ul><li>An activity is put into the Canceling state by a parent activity explicitly, or because an exception in executing activity. </li></ul><ul><li>The Closed state is the last and final state of an activity . </li></ul><ul><li>From Closed states if your business logic demands it can goes to Compensating sate and return back to Closed state. </li></ul><ul><li>If an exception is thrown during executing, compensating and canceling state then transmit to Faulting state. </li></ul><ul><li>An activity can’t move from Closed state to Executing state. </li></ul><ul><li>An activity may only close when all children activities are either in their Closed or Initialized states. </li></ul>
  22. 22. Activity Execution Context <ul><li>Every activity has an activity execution context that represents the execution environment of the activity. </li></ul><ul><ul><li>An ActivityExecutionContext (AEC) is the execution environment that is created for an activity when the host application calls the Start() method. </li></ul></ul><ul><ul><li>The ActivityExecutionContext (AEC) provides a composite activity with the ability to execute ( ExecuteActivity() ) or Cancel ( CancelActivity() ) a child activity. It can also close itself through the CloseActivity() method. Remaining all other activity states are controlled by the workflow runtime. </li></ul></ul><ul><ul><li>The AEC has a property called ExecutionContextManager that enables it to generate new AECs. These AECs are generated every time a parent activity, such as a WhileActivity , ReplicatorActivity , or ConditionedActivityGroup activity, runs its child activities more than once. </li></ul></ul><ul><ul><li>Certain composite activities, such as ReplicatorActivity , WhileActivity activities, create multiple instances of their child activities during execution, and each child activity has its own execution context that it runs in. </li></ul></ul><ul><ul><li>Every activity also transitions through various states during its lifetime. Some transitions are controlled by the workflow runtime engine , while others can be user controlled. </li></ul></ul>
  23. 23. Activity Properties <ul><li>There are two types of activity properties: </li></ul><ul><ul><li>Meta Properties: These properties are immutable at runtime, so the properties must be set to a literal value at design time. (Eg: Name property of Activity). </li></ul></ul><ul><ul><li>Instance Properties: These properties can be set at design time, or the property can be bound to instance data. ( Eg: Error string on a SuspendActivity ). </li></ul></ul><ul><ul><ul><li>If the property is bound to instance data, in which case the actual value is not determined until runtime. </li></ul></ul></ul><ul><ul><ul><li>These properties can also be modified directly during workflow execution. </li></ul></ul></ul><ul><li>The dependency properties provide a centralized repository of a workflow's state. It is basically a hash table. </li></ul><ul><li>An attached property is one the property is defined in one class/activity but used on another activity or class. These properties are specialized form of dependency properties . </li></ul><ul><ul><li>Here you need to register the property. To register an attached property you can use RegisterAttached() method of the DependencyProperty class. </li></ul></ul>
  24. 24. Activity Companion Classes <ul><li>Activity also have companion classes: </li></ul><ul><li>The additional features are added to activities via attributes . </li></ul><ul><ul><li>[ ToolboxItem (typeof(ActivityToolboxItem))] </li></ul></ul><ul><ul><li>[ Designer (typeof(MyDesigner))] </li></ul></ul><ul><ul><li>p ublic partial class MyActivity : Activity { </li></ul></ul><ul><ul><li>} </li></ul></ul>Activity Designer Validator CodeGenerator Serializer
  25. 25. Workflows & Workflow Runtime
  26. 26. Workflows <ul><li>You can write workflows directly in code , in markup or combination of both . </li></ul><ul><ul><li>WWF enables model-driven workflow development , providing natural design visibility and hiding system-level concerns such as transactions , state management , and concurrency control . </li></ul></ul><ul><li>The two primary facets of programming workflows: </li></ul><ul><ul><li>Designing workflows and their activities. </li></ul></ul><ul><ul><li>Using workflows in your application. </li></ul></ul><ul><li>A Workflow is simply a list of activities . </li></ul><ul><ul><li>Each workflow instance is uniquely identified by its InstanceId property. This is a GUID and that can be assigned by the runtime. </li></ul></ul><ul><ul><li>The class responsible for executing workflow is the WorkflowRuntime class. </li></ul></ul><ul><ul><li>You can access your specific workflow from the runtime by using the GetWorkFlow( guid ) method of the WorkflowRuntime Class. </li></ul></ul><ul><li>There are two types of Workflows available in WF. </li></ul><ul><ul><li>Sequential Workflows </li></ul></ul><ul><ul><li>State Machine Workflows </li></ul></ul><ul><ul><li>Data-driven Workflows </li></ul></ul><ul><li>Workflow itself is just another type of activity. </li></ul>
  27. 27. Workflow Runtime <ul><li>A Workflow doesn’t exists on its own. A workflow is always executed within the context of workflow runtime . </li></ul><ul><ul><li>This runtime support is available by instantiating the WorkflowRuntime class. </li></ul></ul><ul><ul><li>The workflow runtime contains methods to construct instances of workflows. </li></ul></ul><ul><ul><li>There are six various CreateWorkflow() methods used to construct the workflow instances, These methods returns the workflow instance object. </li></ul></ul><ul><ul><ul><li>In addition runtime also contains methods for reloading a workflow instance and enumerating all running instances. </li></ul></ul></ul><ul><ul><li>To start running your workflow, you need to call Start() method from the returned WorkflowInstance object. Because sequential workflow doesn’t rely on an external event to run, it begins immediately. </li></ul></ul><ul><ul><li>The workflow runtime also supports number of events that are raised while workflows are executing. The events are: </li></ul></ul><ul><ul><ul><li>WorkflowCreated : Raised when new workflow instance is constructed. </li></ul></ul></ul><ul><ul><ul><li>WorkflowIdled : Raised when a workflow is awaiting input. </li></ul></ul></ul><ul><ul><ul><li>WorkflowCompleted: This event is raised when the workflow has finished. </li></ul></ul></ul>
  28. 28. Events Raised by WWF Runtime <ul><li>The following table lists the events that can be raised by the Workflow runtime engine that pertain to the workflow runtime engine itself are: </li></ul><ul><ul><li>ServicesExceptionNotHandled </li></ul></ul><ul><ul><li>Started </li></ul></ul><ul><ul><li>Stopped </li></ul></ul><ul><li>The following events are the workflow instance events that can be raised by the workflow runtime engine . </li></ul><ul><ul><li>WorkflowAborted </li></ul></ul><ul><ul><li>WorkflowCompleted </li></ul></ul><ul><ul><li>WorkflowCreated </li></ul></ul><ul><ul><li>WorkflowIdled </li></ul></ul><ul><ul><li>WorkflowLoaded </li></ul></ul><ul><ul><li>WorkflowPersisted </li></ul></ul><ul><ul><li>WorkflowResumed </li></ul></ul><ul><ul><li>WorkflowStarted </li></ul></ul><ul><ul><li>WorkflowSuspended </li></ul></ul><ul><ul><li>WorkflowTerminated </li></ul></ul><ul><ul><li>WorkflowUnloaded </li></ul></ul>
  29. 29. Passing Parameters to Workflow <ul><li>Passing parameters to workflow is some what different. </li></ul><ul><ul><li>To pass parameters by storing them in a dictionary of name-value pairs and when you construct workflow you pass through this dictionary. </li></ul></ul><ul><ul><li>Dictionary <string, object> parms = new Dictionary <string, object>(); </li></ul></ul><ul><ul><li>params . Add (“OrderID”, 12345); </li></ul></ul><ul><ul><li>WorkflowInstance myWorkflow = wfRuntime. CreateWorkflow (typeof( MyWorkflow ), parms ); </li></ul></ul><ul><ul><li>In name-value pair, the name should match to any one of the public property of workflow. When the name doesn’t correspond to any one of public property on the workflow, then an exception will be thrown. </li></ul></ul><ul><li>Once parameters passed to workflow you need to link these parameters to activities . The process of linking is called binding . </li></ul><ul><ul><li>A bindable property is displayed in the property grid within Visual Studio. By double-clicking on the bind icon on this property grid display a dialog box allows you to select an appropriate property to link to this property. </li></ul></ul>
  30. 30. Returning Result from Workflow <ul><li>When a workflow finishes its execution, the workflow runtime raises the WorkflowCompleted event. </li></ul><ul><ul><li>For this completed event handler the contextual information about the workflow is passed. It contains the data from that workflow. </li></ul></ul><ul><ul><li>private void MyWorkflowCompleted(object sender, EventArgs e) { </li></ul></ul><ul><ul><li>WorkflowCompletedEventArgs we = e as WorkflowCompletedEventArgs; </li></ul></ul><ul><ul><li>KeyValuePair <string, object> parms = we. OutputParameters ; </li></ul></ul><ul><ul><li>//By iterating params you will get the multiple return values from workflow. </li></ul></ul><ul><ul><li>} </li></ul></ul>
  31. 31. Characteristics of Workflow <ul><li>In workflows, Tracking is the ability to specify and capture information about workflow instances and store that information as the instances execute. </li></ul><ul><ul><li>WWF provides the SqlTrackingService , it stores the collected tracking information in SQL database. </li></ul></ul><ul><ul><li>In addition you can also write your own tracking service also. </li></ul></ul><ul><ul><li>When a new workflow is created, the tracking service requests a tracking channel to be associated with that workflow. </li></ul></ul><ul><ul><li>All tracking information from the workflow is then sent to this tracking channel. </li></ul></ul><ul><ul><li>The tracking service can track three types of events: </li></ul></ul><ul><ul><ul><li>Workflow Instance Events, </li></ul></ul></ul><ul><ul><ul><li>Activity events </li></ul></ul></ul><ul><ul><ul><li>User Events. </li></ul></ul></ul><ul><ul><li>In addition you can also configure type and amount of information that your service wants to receive for a particular workflow instance or type of workflow by providing a tracking profile . </li></ul></ul>
  32. 32. Characteristics of Workflow <ul><li>Activities can be a compensatable activity. </li></ul><ul><ul><li>Compensation is the act of undoing any actions that were performed by a successfully completed compensatable activity because of an exception in a workflow. </li></ul></ul><ul><li>WWF framework simplifies the process of creating stateful, long-running , persistent workflow applications. </li></ul><ul><ul><li>The workflow runtime engine manages workflow execution and enables workflows to remain active for long periods of time and survive application restarts. This durability is the key tenet of WWF. </li></ul></ul><ul><li>Workflows, activities, and rules can be serialized and deserialized . </li></ul><ul><ul><li>The serialization enables the workflow in workflow markup files, and view their properties, fields , and events in a workflow designer. </li></ul></ul><ul><ul><li>WWF provides default serialization capabilities for standard activities, or you can create your own serializer for custom activities. </li></ul></ul><ul><li>WWF enables you to dynamically update your workflow instance and declarative rules during runtime. Before activities are scheduled for execution, you can change expected behavior, flow control and so on. </li></ul>
  33. 33. Serialization in Workflow <ul><li>The WWF framework provides a serialization support that is used to serialize and deserialize workflows. </li></ul><ul><ul><li>WWF provides default serialization capabilities for standard activities, or you can create your own serializer for custom activities. </li></ul></ul><ul><ul><li>By default, a workflow is serialized to workflow markup . </li></ul></ul><ul><ul><li>Workflow markup is the serialized form of object hierarchies. </li></ul></ul><ul><ul><li>With DesignerSerializer attribute; specify custom serializer to custom activity. </li></ul></ul><ul><li>WWF infrastructure provides the following classes to support serialization </li></ul><ul><ul><li>WorkflowMarkupSerializer </li></ul></ul><ul><ul><li>ActivityMarkupSerializer </li></ul></ul><ul><ul><li>CompositeActivityMarkupSerializer </li></ul></ul><ul><ul><li>The serializers for activities or any other custom serializers for custom activities must inherit from WorkflowMarkupSerializer class. </li></ul></ul><ul><ul><li>ActivityMarkupSerializer class inherits from WorkflowMarkupSerializer . This serializer is used to serialize all basic activities ( i.e., not composite activities ). </li></ul></ul><ul><ul><li>CompositeActivityMarkupSerializer derived from ActivityMarkupSerializer class provides serialization for composite activities. </li></ul></ul>
  34. 34. Services in Workflow <ul><li>The workflow runtime engine uses many services when a workflow instance runs. Some of the services the runtime engine uses are: </li></ul><ul><ul><li>Persistence Service </li></ul></ul><ul><ul><li>Scheduling Service </li></ul></ul><ul><ul><li>Transaction Service </li></ul></ul><ul><ul><li>Tracking Service </li></ul></ul><ul><ul><li>These service components are pluggable, which allows applications to provide these services in ways that are unique to their execution environment. </li></ul></ul><ul><ul><li>In addition, Workflow provided services you can also create custom services to extend the workflow foundation platform by deriving from base service classes . </li></ul></ul><ul><li>Host processes can communicate with workflows by exchanging the data through custom local communication services . </li></ul><ul><ul><li>Local communication services implement user-defined interfaces that defines methods & events that will be passed between the workflow and the host process </li></ul></ul><ul><ul><li>Host processes can also interact with a specific activity in a specific workflow instance by using a unique ID that is passed between the host process and the workflow as an event argument. This is known as correlation . </li></ul></ul>
  35. 35. Workflow Performance Monitoring <ul><li>You can monitor workflow performance by using Performance ( Perfmon.exe ) on Windows XP or Vista. </li></ul><ul><ul><li>By using this performance monitor tool , you can configure performance counters to record performance data and set system alerts to notify you when a specified counter's value is above or below defined threshold. </li></ul></ul><ul><ul><li>WWF provides a set of performance counters with the WWF performance object that you can use to track the performance of the workflow runtime as it executes workflow instances. Some of the performance counters are: </li></ul></ul><ul><ul><ul><li>Workflows Completed </li></ul></ul></ul><ul><ul><ul><li>Workflows Created </li></ul></ul></ul><ul><ul><ul><li>Workflows Created/sec </li></ul></ul></ul><ul><ul><ul><li>Workflows Executing </li></ul></ul></ul><ul><ul><ul><li>Workflows In Memory </li></ul></ul></ul><ul><ul><li>WWF performance counters are enabled by default. You can disable them by either setting the EnablePerformanceCounters attribute to false in a workflow configuration file, or changing it programmatically in the WorkflowRuntimeSection class property EnablePerformanceCounters . </li></ul></ul><?xml version=&quot;1.0&quot;?> <configuration> <configSections> <section name=&quot; CustomWorkflowRuntimeSettings &quot; type=“xxx&quot; /> </configSections> < CustomWorkflowRuntimeSettings Name=&quot;Workflow1&quot; EnablePerformanceCounters =&quot;false&quot;> <!-- Define common parameters & declare services --> </CustomWorkflowRuntimeSettings> </configuration>
  36. 36. Workflow Configuration Files <ul><li>WWF host application can use configuration files to control the behavior of a WorkflowRuntime object. </li></ul><ul><ul><li>Within the configuration file crate a configuration section as shown below: </li></ul></ul><ul><ul><li><configuration> </li></ul></ul><ul><ul><li>< configSections > </li></ul></ul><ul><ul><li>< section name =“ MyWFRuntimeConfig &quot; type =&quot;System.Workflow.Runtime.Configuration.WorkflowRuntimeSection, System.Workflow.Runtime, Version=3.0.00000.0, Culture=neutral, PublicKeyToken 31bf3856ad364e35&quot; /> </li></ul></ul><ul><ul><li></ configSections > </li></ul></ul><ul><ul><li></configuration> </li></ul></ul><ul><ul><li>Your configuration file can contain multiple configuration sections only one section is used during instantiation of WorkflowRuntime. </li></ul></ul><ul><ul><li>In this configuration, we are defining the services , when you create an instance of a WorkflowRuntime object these services are added to runtime. ( Next slide ) </li></ul></ul><ul><ul><ul><li>In addition to this configuration file we will add services programmatically also. </li></ul></ul></ul>
  37. 37. Workflow Configuration Files <ul><li>Once the configuration section has declared now add the configuration information section to your configuration file as shown below: </li></ul><ul><ul><li>< MyWFRuntimeConfig Name=&quot;SampleApplication&quot;> </li></ul></ul><ul><ul><li>< CommonParameters > </li></ul></ul><ul><ul><li><add type =&quot;ConnectionString&quot; type =“SQL Connstring values&quot; /> </li></ul></ul><ul><ul><li></ CommonParameters > </li></ul></ul><ul><ul><li>< Services > </li></ul></ul><ul><ul><li><add type =&quot;DefaultWorkflowSchedulerService&quot; maxQueuedWorkItems =&quot;20&quot;/> </li></ul></ul><ul><ul><li><add type =&quot;SharedConnectionWorkflowTransactionService” /> </li></ul></ul><ul><ul><li><add type =&quot;SqlWorkflowPersistenceService” UnloadOnIdle =&quot;false&quot;/> </li></ul></ul><ul><ul><li></ Services > </li></ul></ul><ul><ul><li></ MyWFRuntimeConfig > </li></ul></ul><ul><ul><li>The CommonParameters element defines any parameters that are used globally across multiple services. </li></ul></ul><ul><li>In your host application, while creating runtime object pass name of the configuration section as a parameter to the WorkflowRuntime constructor. </li></ul><ul><li>WorkflowRuntime runtime = new WorkflowRuntime(&quot; MyWFRuntimeConfig &quot;); </li></ul>
  38. 38. Enable Workflow Logging <ul><li>Using the configuration file, you can output WWF logging information: </li></ul><ul><li>< system.diagnostics > </li></ul><ul><li><switches> </li></ul><ul><li> <add name=&quot;System.Workflow LogToFile&quot; value=“All&quot; /> </li></ul><ul><li> <add name=&quot;System.Workflow.Runtime&quot; value=&quot;All&quot; /> </li></ul><ul><li> <add name=&quot;System.Workflow.Runtime.Hosting&quot; value=&quot;All&quot; /> </li></ul><ul><li> <add name=&quot;System.Workflow.Runtime.Tracking&quot; value=&quot;All&quot; /> </li></ul><ul><li> <add name=&quot;System.Workflow.Activities&quot; value=&quot;All&quot; /> </li></ul><ul><li> <add name=&quot;System.Workflow.Activities.Rules&quot; value=&quot;All&quot; /> </li></ul><ul><li></switches> </li></ul><ul><li></ system.diagnostics > </li></ul><ul><ul><li>The first add node enables logging to a file. The file is created in your host application directory using the name WorkflowTrace.log . </li></ul></ul><ul><ul><li>The other option is to enable logging to a TraceListener by setting the name parameter equal to &quot; System.Workflow LogToTraceListener &quot;. </li></ul></ul>
  39. 39. Thank You !