다음을 통해 공유


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)인 경우

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 클래스에서 파생된 서비스입니다. 핵심 서비스 워크플로 런타임 엔진이 실행 되 고 있지 않으면 추가할 수 있습니다. 즉, IsStartedfalse합니다. WorkflowRuntime은 호스트에서 실행 중인 애플리케이션이나 다른 워크플로에서 사용할 수 있는 다른 서비스에 대한 스토리지 컨테이너로 사용될 수도 있습니다. 워크플로 런타임 엔진이 시작된 후 WorkflowRuntimeService 클래스에서 파생된 비핵심 서비스를 추가하면 AddService가 해당 서비스에 의해 구현된 Start 메서드를 호출합니다.

참고

AddServiceType이 동일한 두 개의 서비스를 WorkflowRuntime에 추가할 수 없다는 제한을 적용합니다. 그러나 동일한 기본 클래스에서 파생된 서비스는 여러 개 추가할 수 있습니다. WorkflowRuntime의 서비스 기본 클래스인 WorkflowSchedulerService 클래스, WorkflowCommitWorkBatchService 클래스 및 WorkflowPersistenceService 클래스에서 각각 하나의 서비스만 파생될 수 있습니다. 이러한 클래스 중 하나에서 파생된 여러 서비스(예: 두 개의 지속성 서비스)를 추가하면 StartRuntimeInvalidOperationException을 throw합니다.

적용 대상