TransactionFlowAttribute属性设置为Mandatory,但通道的绑定未配置TransactionFlowBindingElement
问题描述:
我有一个很大的问题。我正在尝试创建一个可用于分布式事务的Web服务。
以下所有代码位于Web服务(从客户端调用的Web服务)的服务器端。TransactionFlowAttribute属性设置为Mandatory,但通道的绑定未配置TransactionFlowBindingElement
[ServiceContract]
public interface IClientOperations
{
[OperationContract]
[ServiceKnownType(typeof(TriggerExecInput))]
[ServiceKnownType(typeof(TriggerExecOutput))]
[TransactionFlow(TransactionFlowOption.Mandatory)]
TriggerExecOutput TriggeredProfileDataUpdate(TriggerExecInput triggerInputData, bool isST3StatusActive);
在web.config文件,这个:
<services>
<service name="ClientOperationsService" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="wsHttpBinding"
bindingConfiguration="wsHttpBinding_Common" contract="SL.STAdmin.Applications.WebAPI.IClientOperations"/>
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="wsHttpBinding_Common" transactionFlow="true">
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- 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"/>
</behavior>
</serviceBehaviors>
</behaviors>
如果我右键单击.svc文件并点击“浏览器查看”我得到
我在接口写了这个出现以下错误
Exception Details: System.InvalidOperationException: At least one operation on the 'ClientOperations' contract is configured with the TransactionFlowAttribute attribute set to Mandatory but the channel's binding 'BasicHttpBinding' is not configured with a TransactionFlowBindingElement. The TransactionFlowAttribute attribute set to Mandatory cannot be used without a TransactionFlowBindingElement.
我有其他不使用事务的.svc文件。 他们都很好。 我不明白为什么它会在我指示它使用其他绑定类型时尝试使用BasicHttpTransaction。
任何人有任何想法我做错了什么? 预先感谢您。
答
你的web.config你<system.serviceModel>
元素中添加此:
<protocolMapping>
<add scheme="http" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding_Common"/>
</protocolMapping>
答
你需要做的几件事情让工作事务。 的transactionflow添加到您的操作
[OperationContract]
[TransactionFlow(TransactionFlowOption.Mandatory)]
void TransactionSupported(int id, string name);
之后,你添加一个operationbehavior到您的实现
[OperationBehavior(TransactionScopeRequired = true)]
public void TransactionSupported(int id, string name)
{
...
}
在您的配置文件,你需要的交易流程添加到您的主机绑定
<system.serviceModel>
...
<bindings>
<netNamedPipeBinding> --> Your binding (don't use basicHttpBinding)
<binding transactionFlow="true"/>
</netNamedPipeBinding>
</bindings>
</system.serviceModel>
最后但并非最不重要的是,您需要设置客户端的事务流才能使其工作。在我的示例中,我在我的单元测试中的代码中执行此操作,我认为您也可以在配置文件中对您的客户端进行配置。
var factory = new ChannelFactory<IService>(callback,
new NetNamedPipeBinding() { TransactionFlow = true },
new EndpointAddress("net.pipe://localhost/ping"));
'BasicHttpTransaction'不是绑定,我想你的意思是'BasicHttpBinding' – 2016-04-22 10:54:26