Click here to Skip to main content
15,885,216 members
Articles / Web Development / ASP.NET

Navigational Workflows Unleashed in WWF/ASP.NET 3.5

Rate me:
Please Sign up or sign in to vote.
4.97/5 (42 votes)
21 Oct 2008CPOL18 min read 224.9K   1.6K   165  
Case-study on the internals of a Navigational Workflow engine for a fictional dating website called “World Wide Dating”.
using System;
using System.Workflow.Runtime;
using System.Workflow.Activities;

namespace DateSite
{
    public class Global : System.Web.HttpApplication
    {
        /// <summary>
        /// This method fires when the application is first started and is responsible for
        /// setting up the workflow runtime to be hosted by the asp.net application. It creates
        /// the workflow runtime with the given settings from the web.config. It then proceeds
        /// to add the local services defined in the web.config. Finally it starts the workflow
        /// runtime and stores the instance in an application variable. Only one instance of the
        /// workflow runtime can be running in a single application domain.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Application_Start(object sender, EventArgs e)
        {
            // create an instance of workflow runtime, loading settings from web.config
            WorkflowRuntime workflowRuntime = new WorkflowRuntime(WorkflowManager.WorkflowRuntimeKey);

            // add the external data exchange service to the runtime to allow for local services
            ExternalDataExchangeService exchangeService = new ExternalDataExchangeService(WorkflowManager.LocalServicesKey);
            workflowRuntime.AddService(exchangeService);

            // start the workflow runtime
            workflowRuntime.StartRuntime();

            // save the runtime for use by the entire application
            Application[WorkflowManager.WorkflowRuntimeKey] = workflowRuntime;
        }

        /// <summary>
        /// This method fires when the application stops. It stops the workflow runtime and 
        /// disposes of the resources it was using.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Application_End(object sender, EventArgs e)
        {
            // obtain reference to workflow runtime
            WorkflowRuntime workflowRuntime = Application[WorkflowManager.WorkflowRuntimeKey] as WorkflowRuntime;

            // stop the runtime
            if (workflowRuntime != null)
            {
                workflowRuntime.StopRuntime();
                workflowRuntime.Dispose();
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Founder Turing Inc.
United States United States

Comments and Discussions