我目前正在使用BehaviorExtensionElement加载ServiceDehavior,其中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;
}
}
没有触发任何事件,只是说我在这个特定场景中引用运行时实例的方式是错误的。
有人知道这样做的方法吗?提前谢谢。
答案 0 :(得分:2)
WorkflowRuntime和WorkflowRuntimeBehavior是WF3工件,但您的问题被标记为WF4,因此我假设您使用的是WF4。
在WF4中,执行此操作的方法是使用自定义TrackingParticipant并将其添加到WorkflowServiceHost的WorkflowExtensions集合。