方法 : ワークフロー サービスを追加または削除する
ワークフロー ランタイムのサービスを追加および削除できます。WorkflowRuntime クラスに定義されている AddService メソッドを使用して、サービスを追加できます。サービスを削除するには、同じく WorkflowRuntime クラスに定義されている RemoveService メソッドを使用します。
ワークフロー ランタイム エンジンへのサービスの追加
ワークフロー エンジンが WorkflowRuntime クラスに定義されている StartRuntime メソッドを使用して実行を開始する前に、そのワークフローに必要なサービスを追加できます。新しいサービスを追加するには、サービス オブジェクトの新しいインスタンスを作成し、WorkflowRuntime クラスに定義されている AddService メソッドを呼び出します。その際、サービス オブジェクトをパラメータとして渡します。ランタイム エンジンの作成と開始、「カスタム追跡サービスの作成」で説明している EventLogTrackingService サービスのインスタンスの作成、およびこのサービスをワークフロー ランタイム エンジンに追加する方法を、次の例に示します。
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;
namespace WorkflowApplication
{
class WorkflowHostExample
{
static void Main(string[] args)
{
// Create the runtime and EventLogTrackingService objects.
WorkflowRuntime runtime = new WorkflowRuntime();
EventLogTrackingService eventlogService = new EventLogTrackingService();
// Add the EventLogTrackingService and start the runtime.
runtime.AddService(eventlogService);
runtime.StartRuntime();
...
runtime.StopRuntime();
}
}
}
ワークフロー ランタイム エンジンからのサービスの削除
ワークフロー ランタイム エンジンにサービスを追加できるのと同様に、サービスを削除することができます。これは、WorkflowRuntime クラスに定義されている RemoveService メソッドを呼び出すことで実行します。このメソッドに渡すパラメータは、削除するサービスのインスタンスです。サービスを削除できるのは、ワークフロー ランタイム エンジンが実行されていないときだけです。このため、最初に StopRuntime メソッドを呼び出してサービスを削除し、次に StartRuntime を呼び出してランタイムを再開する必要があります。前に示した例に基づいて、そこから EventLogTrackingService サービスを削除する方法を、次の例に示します。
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;
namespace WorkflowApplication
{
class WorkflowHostExample
{
static void Main(string[] args)
{
// Create the runtime and EventLogTrackingService objects.
WorkflowRuntime runtime = new WorkflowRuntime();
EventLogTrackingService eventlogService = new EventLogTrackingService();
// Add the EventLogTrackingService and start the runtime.
runtime.AddService(eventlogService);
runtime.StartRuntime();
...
// Stop the runtime and remove the EventLogTrackingService.
runtime.StopRuntime();
runtime.RemoveService(eventlogService);
}
}
メモ : |
---|
ランタイム エンジンの実行中は、ランタイム エンジン自身が作成したサービスは削除できません。ランタイムが実行を開始するときには、既定のサービスが追加されます。それらのサービスは、ワークフローの実行を管理するために必要です。 |
次のサービスと、この種類から派生するサービスは、ランタイム エンジンの実行中は削除できません。
構成ファイルを使用したサービスの追加と削除の方法については、「チュートリアル : Windows Workflow Foundation ランタイムのホスティング」の「タスク 2: App.Config を使用したランタイム サービスの構成」、および「Workflow Configuration Formats」を参照してください。
関連項目
参照
WorkflowCommitWorkBatchService
WorkflowPersistenceService
TrackingService
WorkflowSchedulerService
WorkflowLoaderService
概念
その他の技術情報
Copyright © 2007 by Microsoft Corporation.All rights reserved.