Hosting Workflows in ASP.NET Applications (From Microsoft Elearning)

Hosting Workflows
Hosting Workflows in ASP.NET Applications

If you want your application to have a Web interface, you can host your workflows within an ASP.NET application. To do this you must satisfy the following requirements. Click each requirement to view more details.

 

Desktop applications require one instance of the workflow runtime for all the users of the application. It is possible to create this in the Application_Start event in the Global.asax file. You can access the runtime object in the following way:

[Visual Basic]Public Shared wr As WorkflowRuntime = New WorkflowRuntime()
[Visual C#]static WorkflowRuntime wr = new WorkflowRuntime();

For desktop applications, you pass information into the workflow by creating a Dictionary object or name/value pairs. Each name must correspond to the name of a public property in your workflow class.

[Visual Basic]Dim parameters As New Dictionary(Of String, String)
Parameters.Add("UserName", "Fred")
Parameters.Add("Password", "P@ssw0rd")
[Visual C#]Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("UserName", "Fred");
parameters.Add("Password", "P@ssw0rd");

For desktop applications, you must register an event handler to handle the output from the workflow. Then you can start the workflow instance:

[Visual Basic]AddHandler wr.WorkflowCompleted, AddressOf LoginCompleted
Dim t As Type = TypeOf Samples.LoginWorkflow
Dim instance As WorkflowInstance = wr.CreateWorkflow(t, parameters)
instance.Start()
[Visual C#]wr.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(LoginCompleted);
Type t = typeof(Samples.LoginWorkflow);
WorkflowInstance instance = wr.CreateWorkflow(t, parameters);
instance.Start();

If you use the WorkflowWebRequestContext object to access the workflow runtime, you cannot add services such as persistence or scheduling services because the workflow is already started. If you try to add services to the runtime when it has already started it will generate an error. Instead, to configure the runtime with services, use the <workflowRuntime> section in the Web.config file:

[Web.config]<configuration>
    <configSections>
        <section name="WorkflowRuntime"
            type="WorkflowRuntimeSection, System.Workflow.Runtime" />
    </configSections>
</configuration>
styles/prem_styles_v1.cssscormcode.jsfindlmsapi.jsgraphics/sh_arrow_open.jpg_fulltext.htc1.95.53.0 topic.textonly
posted @ 2006-11-20 08:12  upzone  阅读(349)  评论(2)    收藏  举报