Adds the specified service to the workflow runtime engine.
Namespace:
System.Workflow.Runtime
Assembly:
System.Workflow.Runtime (in System.Workflow.Runtime.dll)
Visual Basic (Declaration)
Public Sub AddService ( _
service As Object _
)
Dim instance As WorkflowRuntime
Dim service As Object
instance.AddService(service)
public void AddService(
Object service
)
public:
void AddService(
Object^ service
)
public function AddService(
service : Object
)
Parameters
- service
- Type: System..::.Object
An object that represents the service to add.
You can configure the workflow runtime engine by adding core services. Core services are those that derive from any of the following service base classes: the WorkflowSchedulerService class, the WorkflowCommitWorkBatchService class, the WorkflowPersistenceService class, and the TrackingService class. Core services can only be added when the workflow runtime engine is not running; that is, when IsStarted is false. The WorkflowRuntime can also be used as a storage container for other services that may be used by other workflows or by applications running on a host. If you add a non-core service that derives from the WorkflowRuntimeService class after the workflow runtime engine has been started, AddService will call the Start method implemented by that service.
The following code example demonstrates how you can use WorkflowRuntime functionality from a workflow host. It provides example of how to use the AddService method to add an ExternalDataExchangeService and SqlWorkflowPersistenceService to the workflow runtime engine.
This code example is part of the Cancelling a Workflow SDK sample from the Program.cs file. For more information, see Cancelling a Workflow.
Shared Sub Main()
Dim connectionString As String = "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;"
Using workflowRuntime As New WorkflowRuntime()
Dim dataService As New ExternalDataExchangeService()
workflowRuntime.AddService(dataService)
dataService.AddService(expenseService)
workflowRuntime.AddService(New SqlWorkflowPersistenceService(connectionString))
AddHandler workflowRuntime.WorkflowCompleted, AddressOf OnWorkflowCompleted
AddHandler workflowRuntime.WorkflowTerminated, AddressOf OnWorkflowTerminated
AddHandler workflowRuntime.WorkflowIdled, AddressOf OnWorkflowIdled
AddHandler workflowRuntime.WorkflowAborted, AddressOf OnWorkflowAborted
Dim workflowInstance As WorkflowInstance
workflowInstance = workflowRuntime.CreateWorkflow(GetType(SampleWorkflow))
workflowInstance.Start()
waitHandle.WaitOne()
workflowRuntime.StopRuntime()
End Using
End Sub
static void Main()
{
string connectionString = "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;";
using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
{
ExternalDataExchangeService dataService = new ExternalDataExchangeService();
workflowRuntime.AddService(dataService);
dataService.AddService(expenseService);
workflowRuntime.AddService(new SqlWorkflowPersistenceService(connectionString));
workflowRuntime.StartRuntime();
workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
workflowRuntime.WorkflowIdled += OnWorkflowIdled;
workflowRuntime.WorkflowAborted += OnWorkflowAborted;
Type type = typeof(SampleWorkflow1);
WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(type);
workflowInstance.Start();
waitHandle.WaitOne();
workflowRuntime.StopRuntime();
}
}
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0
Reference
Other Resources