WCF 服务中的 TransactionScope 异常
TransactionScope Exception In WCF Service
我正在尝试在 wcf 服务中启用事务流。
但是我收到以下错误:
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.config 上的绑定选项 api
<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 访问,我允许入站和出站,我没有检查是否需要身份验证。
我启用了 XA 交易和 SNA LU 6.2 交易
我已尝试将以下属性添加到我的绑定中:
transactionProtocol="OleTransactions"
在服务和网络上 api。
似乎无法弄清楚问题所在。
事实证明,有 [OperationContract]
属性放置在 WCF 方法调用的方法上,这些方法已经 [OperationContract]
删除了所有 [OperationContract]
属性并仅放置它们关于WCF公开的方法解决了问题。
我正在尝试在 wcf 服务中启用事务流。
但是我收到以下错误:
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.config 上的绑定选项 api
<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 访问,我允许入站和出站,我没有检查是否需要身份验证。 我启用了 XA 交易和 SNA LU 6.2 交易
我已尝试将以下属性添加到我的绑定中:
transactionProtocol="OleTransactions"
在服务和网络上 api。
似乎无法弄清楚问题所在。
事实证明,有 [OperationContract]
属性放置在 WCF 方法调用的方法上,这些方法已经 [OperationContract]
删除了所有 [OperationContract]
属性并仅放置它们关于WCF公开的方法解决了问题。