WorkflowRuntime.AddService(Object) メソッド

定義

指定したサービスをワークフロー ランタイム エンジンに追加します。

public:
 void AddService(System::Object ^ service);
public void AddService (object service);
member this.AddService : obj -> unit
Public Sub AddService (service As Object)

パラメーター

service
Object

追加するサービスを表すオブジェクト。

例外

service が null 参照 (Visual Basic の場合は Nothing) です。

WorkflowRuntime は破棄されています。

service がワークフロー ランタイム エンジンに既に登録されています。

- または -

service はコア サービスであり、ワークフロー ランタイム エンジンは既に実行中 (IsStartedtrue) です。

次のコード例は、ワークフローのホストから WorkflowRuntime の機能を使用する方法を示しています。 ここでは、AddService メソッドを使用して、ExternalDataExchangeServiceSqlWorkflowPersistenceService をワークフロー ランタイム エンジンに追加する方法の例を示しています。

このコード例は、ワークフローの 取り消しサンプルの 一部です。

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();
    }
}
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

注釈

コア サービスを追加することによってワークフロー ランタイム エンジンを構成できます。 コア サービスは、サービス基本クラスである WorkflowSchedulerService クラス、WorkflowCommitWorkBatchService クラス、WorkflowPersistenceService クラス、および TrackingService クラスのいずれかから派生したサービスです。 コア サービスは、ワークフロー ランタイム エンジンが実行されていない場合にのみ追加できます。つまり、 が の場合 IsStarted です falseWorkflowRuntime は、他のワークフロー、またはホストで実行されるアプリケーションが使用できる他のサービスの格納コンテナーとしても使用できます。 WorkflowRuntimeService クラスから派生した非コア サービスをワークフロー ランタイム エンジンの起動後に追加すると、AddService は、そのサービスによって実装された Start メソッドを呼び出します。

注意

AddService には同じ Type のサービスを複数、WorkflowRuntime に追加できないという制限があります。 ただし、同じ基本クラスから派生したサービスであれば、複数追加できます。 WorkflowRuntime のサービス基本クラスである WorkflowSchedulerService クラス、WorkflowCommitWorkBatchService クラス、および WorkflowPersistenceService クラスのそれぞれから派生できるサービスは、1 つだけです。 これらのクラスのいずれかから派生した複数のサービス (たとえば 2 つの永続性サービス) を追加すると、StartRuntimeInvalidOperationException をスローします。

適用対象