在部署到IIS或AppFabric时,如何在Web.config中配置自定义工作流扩展(例如PersistenceParticipant后代)? (对于WF 4)
答案 0 :(得分:5)
您可以在活动的CacheMetadata中或通过服务行为执行此操作,如下所示。
创建一个IServiceBehavior以添加扩展名和BehaviorExtensionElement以加载IServiceBehavior。
public class MyExtensionElement : BehaviorExtensionElement
{
public override Type BehaviorType
{
get
{
return typeof(MyExtensionBehavior);
}
}
protected override object CreateBehavior()
{
return new MyExtensionBehavior();
}
}
public class MyExtensionBehavior : IServiceBehavior
{
public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
{
var host = (WorkflowServiceHost)serviceHostBase;
host.WorkflowExtensions.Add<MyExtension>(() => new MyExtension());
}
}
接下来将其注册为配置中的behaviorExtensions并在服务行为中使用
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="myExtension"
type="MyWorkflowService.MyExtensionElement, MyWorkflowService"/>
</behaviorExtensions>
</extensions>
<behaviors>
<serviceBehaviors>
<behavior>
<myExtension/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>