是否可以定义标准的ServiceHostFactory foreach'工作流'服务(xamlx)
我们的客户可以使用自定义工作流设计器制作自己的工作流程(xamlx)。我们强制将workflowservices与TransportSecurity一起使用WS2007FederationHttpBinding。我们转向WorkflowService的ServiceMetadataBehavior,最后添加一个进行某种类型解析的DataContractResolver。
ServiceHostFactory
public class MyServiceHostFactory : WorkflowServiceHostFactory
{
protected override WorkflowServiceHost CreateWorkflowServiceHost(
System.ServiceModel.Activities.WorkflowService service,
Uri[] baseAddresses)
{
WorkflowServiceHost host = base.CreateWorkflowServiceHost(service, baseAddresses);
foreach (Uri adres in baseAddresses)
{
if (adres.Scheme == "https")
{
WorkflowCreationEndpoint endpoint = new WorkflowCreationEndpoint(
new WS2007FederationHttpBinding("IWorkflowService_ws2007FederationHttpBinding"),
new EndpointAddress(adres));
host.AddServiceEndpoint(endpoint);
PageflowDataContractResolver.AttachDataContractResolver(endpoint);
}
}
var metadataBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
metadataBehavior.HttpGetEnabled = false;
host.WorkflowExtensions.Add(new WorkflowInstanceTracking());
return host;
}
public override ServiceHostBase CreateServiceHost(string constructorString, Uri[] baseAddresses)
{
return base.CreateServiceHost(constructorString, baseAddresses);
}
protected override WorkflowServiceHost CreateWorkflowServiceHost(System.Activities.Activity activity, Uri[] baseAddresses)
{
return base.CreateWorkflowServiceHost(activity, baseAddresses);
}
}
工作流程作为Ron Jacob wrote in this blog存在于数据库中。 “顾问”和/或最终用户可以使用自定义工具创建工作流,但每次他们这样做时都不要忘记在web.config中添加一个不需要的serviceActivation元素。
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false">
<baseAddressPrefixFilters>
<add prefix="http://localhost" />
</baseAddressPrefixFilters>
<serviceActivations>
<add relativeAddress="~/Workflows/test.xamlx" service="Workflows/test.xamlx" factory="Foo.Bar.MyServiceHostFactory" />
</serviceActivations>
</serviceHostingEnvironment>
<protocolMapping>
<add scheme="https" binding="ws2007FederationHttpBinding" />
</protocolMapping>
..
答案 0 :(得分:2)
我认为将你的问题改为:
是正确的有没有办法更改Web应用程序的默认WorkflowServiceHostFactory,以便无配置xamlx激活将使用我的WSHF。
如果我正确理解了您的问题,那么我认为没有办法做到这一点。我快速查看是否有一个地方可以覆盖它但看不到任何地方。实现此目的的另一种方法是在用户上载新工作流时根据需要修改web.config。在运行中编辑web.config应该导致当前正在运行的执行脉冲由现有AppDomain服务,同时创建新的AppDomain以服务对Web应用程序的新请求。因此,不应发生工作流处理的损失。这当然需要一些测试和验证。
<强>更新强> 看起来这可能是可能的。如果将以下内容添加到web.config(来自工作流激活的默认配置)。
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.xaml.hosting"
type="System.Xaml.Hosting.Configuration.XamlHostingSectionGroup, System.Xaml.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="httpHandlers"
type="System.Xaml.Hosting.Configuration.XamlHostingSection, System.Xaml.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</sectionGroup>
</configSections>
<system.xaml.hosting>
<httpHandlers>
<add xamlRootElementType="System.ServiceModel.Activities.WorkflowService, System.ServiceModel.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
httpHandlerType="System.ServiceModel.Activities.Activation.ServiceModelActivitiesActivationHandlerAsync, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add xamlRootElementType="System.Activities.Activity, System.Activities, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
httpHandlerType="System.ServiceModel.Activities.Activation.ServiceModelActivitiesActivationHandlerAsync, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</httpHandlers>
</system.xaml.hosting>
</configuration>
此默认配置使用的ServiceModelActivitiesActivationHandlerAsync类实现如下:
internal class ServiceModelActivitiesActivationHandlerAsync : ServiceHttpHandlerFactory, IServiceModelActivationHandler
{
// Methods
public ServiceHostFactoryBase GetFactory()
{
return new WorkflowServiceHostFactory();
}
}
然后,不要使用ServiceModelActivitiesActivationHandlerAsync,而是自己提供一个实现,它在GetFactory方法中实例化您自己的WorkflowServiceHostFactory。更新上面的web.config以指向您的新httpHandlerType,您应该完成。
我根本没有测试过这个。 IIS可能不会像web.config那样覆盖system.xaml.hosting部分。