WCF服务中的TransactionScope异常

时间:2017-04-12 09:11:25

标签: c# web-services wcf transactionscope nettcpbinding

我在wcf服务中尝试了enble事务流程。

但是我收到以下错误:

  The header 'OleTxTransaction' from the namespace 'http://schemas.microsoft.com/ws/2006/02/tx/oletx' was not understood by the recipient of this message, causing the message to not be processed.  This error typically indicates that the sender of this message has enabled a communication protocol that the receiver cannot process. Please ensure that the configuration of the client's binding is consistent with the service's binding. 

这是我尝试运行的代码的代码段:

var transactionOptions = new TransactionOptions
                                 {
                                     IsolationLevel = IsolationLevel.ReadCommitted
                                 };

using (var transaction = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
        {
            try
            {
                var company = CreateCompanyDto(settings);

                if (settings.Institution.CompletedSetup)
                {
                    _ezFinanceCompanyServiceLibrary.UpdateCompany(company); // This is the wcf call.
                }
                else
                {
                   _ezFinanceCompanyServiceLibrary.CreateCompany(company); // This is the wcf call.
                    CreateDefaultInventroyItems(company.EntityGuid);
                }

                _db.SaveChanges();
                transaction.Complete();

                return true;
            }
            catch (Exception exception)
            {
                _log.Error(exception.Message);
                return false;
            }
        }

这是我在web api的web.config上的绑定选项

<bindings>
  <netTcpBinding>
    <binding name="netTcpBindingbehavior" transactionFlow="true" portSharingEnabled="true" />
  </netTcpBinding>
  <netMsmqBinding>
    <binding name="netMsmqBinding">
      <security mode="None" />
    </binding>
  </netMsmqBinding>
</bindings>

我在wcf的服务界面上有操作合约

[OperationContract]
[TransactionFlow(TransactionFlowOption.Allowed)]
int CreateCompany(CompanyDto newCompany);
[OperationContract]
[TransactionFlow(TransactionFlowOption.Allowed)]
int UpdateCompany(CompanyDto Company);

我在暴露的方法上有以下属性

[OperationBehavior(TransactionScopeRequired = true)]

我在wcf服务中的App.config上的绑定选项

<bindings>
  <netTcpBinding>
    <binding name="netTcpBinding" transactionFlow="true" portSharingEnabled="true" />
  </netTcpBinding>
</bindings>

我启用了网络DTC访问,我允许Inbounnd和Outbound,我没有身份验证要求已检查。 我启用了XA Transactions和SNA LU 6.2交易

我尝试将以下属性添加到我的绑定中:

transactionProtocol="OleTransactions"

在服务和网络API上。

似乎无法弄清问题是什么。

1 个答案:

答案 0 :(得分:0)

事实证明,WCF方法正在调用的方法上放置了[OperationContract]个属性,这些方法已经[OperationContract]删除了所有[OperationContract]属性并且只将它们放在WCF公开的方法解决了这个问题。