1

我目前正在使用 BehaviorExtensionElement 加载一个 ServiceBehavior,其中 ApplyDispatchBehavior 方法设置为:

    public void ApplyDispatchBehavior(ServiceDescription serviceDescription, System.ServiceModel.ServiceHostBase serviceHostBase)
    {
        WorkflowServiceHost host = serviceHostBase as WorkflowServiceHost;
        if (host != null)
        {
            UnityService.CreateContainer();
            host.WorkflowExtensions.Add<IUnityContainer>(delegate { return UnityService.CreateChildContainer(); });

            System.Diagnostics.Debug.WriteLine("NotificationService : Adding extension");

            WorkflowRuntimeBehavior wfbehavior = serviceDescription.Behaviors.Find<WorkflowRuntimeBehavior>();
            WorkflowRuntime runtime = wfbehavior.WorkflowRuntime;

            runtime.WorkflowStarted += runtime_WorkflowStarted;
            runtime.WorkflowCreated += runtime_WorkflowCreated;

            runtime.WorkflowUnloaded += runtime_WorkflowUnloaded;
            runtime.WorkflowSuspended += runtime_WorkflowSuspended;

            runtime.WorkflowCompleted += runtime_WorkflowCompleted;
            runtime.WorkflowAborted += runtime_WorkflowAborted;
            runtime.WorkflowTerminated += runtime_WorkflowTerminated;
        }
    }

没有任何事件被触发,这只能说明我在这个特定场景中引用运行时实例的方式是错误的。

有人知道这样做的方法吗?提前致谢。

4

1 回答 1

2

WorkflowRuntime 和 WorkflowRuntimeBehavior 是 WF3 工件,但您的问题被标记为 WF4,所以我假设您使用的是 WF4。

在 WF4 中,执行此操作的方法是使用自定义 TrackingParticipant 并将其添加到 WorkflowServiceHost 的 WorkflowExtensions 集合中。

于 2010-05-27T05:47:51.230 回答