Managing the Workflow Runtime


Generally, you want to keep one instance of the workflow runtime for your entire application. Doing this in ASP.NET is a bit different from a Windows Forms application. A common way to manage the workflow runtime is to use the Global.asax file and the Application_Start and Application_End event handlers, as follows:

  <%@ Application Language="C#" %> <%@ Import Namespace="System.Workflow.Runtime" %> <script runat="server">     void Application_Start(object sender, EventArgs e)     {         WorkflowRuntime runtime = new WorkflowRuntime("WorkflowRuntime");         runtime.StartRuntime();         Application["WorkflowRuntime"] = runtime;     }     void Application_End(object sender, EventArgs e)     {         WorkflowRuntime runtime = Application["WorkflowRuntime"]             as WorkflowRuntime;         runtime.StopRuntime();         runtime.Dispose();     } </script> 

In this example, the constructor for the WorkflowRuntime class passes a string that is a reference to a section in the Web.config file. The following code shows a sample Web.config file:

  <?xml version="1.0"?> <configuration>   <configSections>     <section name="WorkflowRuntime"         type="System.Workflow.Runtime.Configuration.WorkflowRuntimeSection,         System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral,         PublicKeyToken=31bf3856ad364e35"/>   </configSections>   <appSettings/>   <connectionStrings/>   <WorkflowRuntime>     <Services>       <add         type="System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService,         System.Workflow.Runtime, Version=3.0.0.0, Culture=neutral,         PublicKeyToken=31bf3856ad364e35"/>     </Services>   </WorkflowRuntime>   <system.web>     <compilation debug="true">       <assemblies>         <add assembly="System.Workflow.Activities, Version=3.0.0.0,           Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>         <add assembly="System.Workflow.ComponentModel, Version=3.0.0.0,           Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>         <add assembly="System.Workflow.Runtime, Version=3.0.0.0,           Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>       </assemblies>     </compilation>     <authentication mode="Windows"/>   </system.web> </configuration> 

In this code, the configSections node allows the addition of custom configuration sections. The type attribute of the section node is a pointer to a .NET type that inherits from System.Configuration.ConfigurationSection. By inheriting from this class, other .NET types are able to parse custom configuration sections, which can be included in Web.config and App.config files. The custom configuration section is implemented in the WorkflowRuntime node, which contains a child node that enumerates the runtime services, which should be added automatically. The ManualWorkflowSchedulerService is added because this is an ASP.NET application.



Professional Windows Workflow Foundation
Professional Windows Workflow Foundation
ISBN: 0470053860
EAN: 2147483647
Year: 2004
Pages: 118
Authors: Todd Kitta

Similar book on Amazon
Pro WF: Windows Workflow in .NET 4 (Expert's Voice in .NET)
Pro WF: Windows Workflow in .NET 4 (Expert's Voice in .NET)
Pro WF: Windows Workflow in NET 3.5 (Expert's Voice in .NET)
Pro WF: Windows Workflow in NET 3.5 (Expert's Voice in .NET)
Microsoft  Windows  Workflow Foundation Step by Step (Microsoft Windows Step by Step)
Microsoft Windows Workflow Foundation Step by Step (Microsoft Windows Step by Step)
Essential Windows Workflow Foundation
Essential Windows Workflow Foundation

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net