执行简单的wcf事务应用程序时出现以下错误。
"至少有一项关于' Service1'合约配置为TransactionFlowAttribute属性设置为Mandatory,但是频道的绑定' BasicHttpBinding'未配置TransactionFlowBindingElement。如果没有TransactionFlowBindingElement,则不能使用设置为Mandatory的TransactionFlowAttribute属性。"
我的代码段如下: Iservice1.cs
[OperationContract]
[TransactionFlow(TransactionFlowOption.Mandatory)]
bool PerformCreditTransaction(string creditAccountID, double amount);
[OperationContract, TransactionFlow(TransactionFlowOption.Mandatory)]
bool PerformDebitTransaction(string debitAccountID, double amount);
Service1.svc.cs
[OperationBehavior(TransactionScopeRequired = true)]
public bool PerformCreditTransaction(string creditAccountID, double amount)
{
//my code
}
[OperationBehavior(TransactionScopeRequired = true)]
public bool PerformDebitTransaction(string debitAccountID, double amount)
{
//my code
}
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:2)
basicHttpBinding不支持跨服务边界的事务,因为basicHttpBinding通过不支持WS-AtomicTransaction的SOAP 1.1公开服务。
您需要使用使用SOAP 1.2的wsHttpBinding,因此提供对事务的支持。
答案 1 :(得分:1)
为了将操作设置为TransactionFlowOption.Mandatory
,服务和客户端必须使用事务感知绑定并在绑定上启用事务流。
例如:
<bindings>
<wsHttpBinding>
<binding transactionFlow="true" />
</wsHttpBinding>
</bindings>
以下帖子包含其他信息:
http://www.codeproject.com/Articles/38793/Steps-to-Enable-Transactions-in-WCF
注意:您可能希望在问题中提供绑定配置,以帮助生成更具体的答案。