Task 1: Set up the Web Site Application Files
This task describes how to set up the application Web site and supporting files.
Rather than creating the WorkflowRuntime object in the ASP page (which creates a new runtime with each load of the main page), this task shows how to create a single run-time object when the application starts, and stores it in the Application collection. The ASP page then accesses the existing run-time object.
To set up the application files
Right-click on the ASPNetTutorial Web site in Solution Explorer and select Add Reference. Select the Projects tab, select the WorkflowLibrary project, and select OK.
Right-click on the Web site in Solution Explorer, and select Add New Item…. Select Global Application Class, and click Add. Right-click on the Web site again, select Add New Item…, select Web Configuration File, and click Add. This step creates two new files in the Web site called Global.asax and Web.config.
Copy the following code into the
Application_Start
method in the Global.asax file. This code creates the workflow run-time object, adds necessary services to the run-time object, starts the runtime, and stores the runtime in the application object.// Code that runs on application startup // Get the connection string from Web.config. String connectionString = ConfigurationManager.ConnectionStrings["LocalConnection"].ConnectionString; // Create the workflow runtime. System.Workflow.Runtime.WorkflowRuntime workflowRuntime = new System.Workflow.Runtime.WorkflowRuntime(); // Add the tracking service. workflowRuntime.AddService(new System.Workflow.Runtime.Tracking.SqlTrackingService(connectionString)); // Add the scheduling service. workflowRuntime.AddService(new System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService()); // Add the persistence service. NameValueCollection parameters = new NameValueCollection(); parameters.Add("ConnectionString", connectionString); parameters.Add("UnloadOnIdle", "true"); workflowRuntime.AddService(new System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService(parameters)); // Add the communication service. System.Workflow.Activities.ExternalDataExchangeService dataService = new System.Workflow.Activities.ExternalDataExchangeService(); workflowRuntime.AddService(dataService); dataService.AddService(new WorkflowLibrary.LoanEventService()); // Add the shared connection service. workflowRuntime.AddService(new System.Workflow.Runtime.Hosting.SharedConnectionWorkflowCommitWorkBatchService(connectionString)); // Start the workflow runtime. // (The workflow runtime starts automatically when workflows are started, but // will not start automatically when tracking data are requested.) workflowRuntime.StartRuntime(); // Add the runtime to the application. Application["WorkflowRuntime"] = workflowRuntime;
Copy the following code into the Web.config file. (This code example contains the database connection string used by the application.) The Web.config file contains a setting for the database connection string used by the tracking and persistence services, as well as references to libraries that are used by the pages on the site.
<?xml version="1.0"?> <!-- Note: As an alternative to hand-editing this file, you can use the Web admin tool to configure settings for your application. Use the Website->Asp.Net Configuration option in Visual Studio. A full list of settings and comments can be found in machine.config.comments usually located in \Windows\Microsoft.NET\Framework\v2.x\Config --> <configuration> <appSettings/> <connectionStrings> <add name="LocalConnection" connectionString="Initial Catalog=SqlPersistence;Data Source=localhost;Integrated Security=SSPI;" /> </connectionStrings> <system.web> <!-- Set compilation debug="true" to insert debugging symbols into the compiled page. Because this affects performance, set this value to true only during development. --> <compilation debug="true"> <assemblies> <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> <add assembly="System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> <add assembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <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"/> <add assembly="Microsoft.Build.Tasks, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> <add assembly="System.Messaging, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> <add assembly="System.Runtime.Remoting, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> <add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="Microsoft.Build.Utilities, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> <add assembly="Microsoft.Build.Framework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation> <!-- The <authentication> section enables configuration of the security authentication mode used by ASP.NET to identify an incoming user. --> <authentication mode="Windows"/> <!-- The <customErrors> section enables configuration of what to do if/when an unhandled error occurs during the execution of a request. Specifically, it enables developers to configure HTML error pages to be displayed in place of an error stack trace. <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors> --> </system.web> </configuration>
Copyright © 2007 by Microsoft Corporation. All rights reserved.
Last Published: 2010-03-04