简体   繁体   中英

TransactionScope Exception In WCF Service

I'm trying enble transaction flow in a wcf service.

However I get the following error:

  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. 

This is a code snippet of the code I'm trying to run:

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;
            }
        }

this is my binding options on the web.config of the web api

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

I have the Operation contracts on my service interface in the wcf

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

I have the following attribute on my exposed methods

[OperationBehavior(TransactionScopeRequired = true)]

My bindings options on the App.config in the wcf service

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

I have enabled the Network DTC access, I allow Inbounnd and Outbound, I have no authentication Required checked. I have enabled XA Transactions and SNA LU 6.2 Transactions

I have tried adding the following attribute to my bindings:

transactionProtocol="OleTransactions"

on both the service and web api.

Cannot seem to figure out what the problem is.

原来,有[OperationContract]放在了正在由WCF方法已经有了调用的方法属性[OperationContract]删除所有[OperationContract]属性,只有把它们暴露在WCF解决问题的方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM