2014-11-05 34 views
1

我在執行我的簡單wcf事務應用程序時遇到以下錯誤。爲什麼我的WCF事務不能正常工作?

「的‘服務1’合同上的至少一個操作被配置成與所述TransactionFlowAttribute屬性設置爲強制性的,但該通道的結合‘basicHttpBinding的’不與TransactionFlowBindingElement構成。該TransactionFlowAttribute屬性設置爲強制性未經TransactionFlowBindingElement不能使用「。

我的代碼片斷如下: 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 
     } 

任何一個可以幫我解決這個問題?

回答

2

basicHttpBinding不支持跨服務邊界的事務,因爲basicHttpBinding通過SOAP 1.1公開了不支持WS-AtomicTransaction的服務。

您需要使用使用SOAP 1.2的wsHttpBinding,因此爲事務提供支持。

1

爲了將操作設置爲TransactionFlowOption.Mandatory,服務和客戶端必須使用事務感知綁定並在綁定上啓用事務流。
例如:

<bindings> 
    <wsHttpBinding> 
    <binding transactionFlow="true" /> 
    </wsHttpBinding> 
</bindings> 

以下帖子包含的其他信息:
http://www.codeproject.com/Articles/38793/Steps-to-Enable-Transactions-in-WCF

注意:您可能想提供問題的綁定配置,以幫助產生更具體的答案。