问题
I'm trying to duplicate the functionality below using web.config since I'm using webserver hosted .xamlx services
host.WorkflowExtensions.Add(new HiringRequestInfoPersistenceParticipant());
I've tried the following from what I've been able to gather searching, but no satisfaction.
<extensions>
<behaviorExtensions>
<add name="sqlTracking"
type="ApprovalService.Persistence.HiringRequestInfoPersistenceParticipant, ApprovalService.Persistence" />
</behaviorExtensions>
</extensions>
Any help would be deeply appreciated.
Here is my updated web.config
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="sqlTracking"
type="ApprovalService.HiringInfoElement, ApprovalService"/>
</behaviorExtensions>
</extensions>
<services>
<service name="ApprovalService" behaviorConfiguration="ApprovalServiceBehavior">
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ApprovalServiceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
<sqlWorkflowInstanceStore connectionStringName="WorkflowPersistence" />
<workflowIdle timeToPersist="0" timeToUnload="0:05:0"/>
<sqlTracking/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
This all compiles and runs but the custom persistance object never get's called.
回答1:
Did you add the sqlTracking behavior to your service behavior section?
The following is a working example
public class StringWriterElement : BehaviorExtensionElement
{
public override Type BehaviorType
{
get { return typeof(StringWriterBehavior); }
}
protected override object CreateBehavior()
{
return new StringWriterBehavior();
}
}
public class StringWriterBehavior : IServiceBehavior
{
public void ApplyDispatchBehavior(ServiceDescription serviceDescription,
ServiceHostBase serviceHostBase)
{
var host = (WorkflowServiceHost)serviceHostBase;
host.WorkflowExtensions.Add<TextWriter>(() => new StringWriter());
}
}
And the web.config:
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="stringWriter"
type=" MyWorkflowService.StringWriterElement, MyWorkflowService"/>
</behaviorExtensions>
</extensions>
<services>
<service name="OrderWorkflow“
behaviorConfiguration="OrderWorkflowBehavior">
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="OrderWorkflowBehavior">
<serviceMetadata httpGetEnabled="True"/>
<stringWriter />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
来源:https://stackoverflow.com/questions/7558713/how-do-i-add-a-custom-persistenceioparticipant-for-webserver-hosted-xamlx-servi