我正在尝试在 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 服务中应用程序.config 上的绑定选项
<bindings>
<netTcpBinding>
<binding name="netTcpBinding" transactionFlow="true" portSharingEnabled="true" />
</netTcpBinding>
</bindings>
我已启用网络 DTC 访问,我允许 Inbounnd 和出站,我没有选中身份验证要求。我已启用 XA 事务和 SNA LU 6.2 事务
我尝试将以下属性添加到我的绑定中:
transactionProtocol="OleTransactions"
在服务和 Web API 上。
似乎无法弄清楚问题是什么。
事实证明,WCF 方法调用的方法上放置了[OperationContract]
属性,这些方法已经具有删除所有[OperationContract]
属性并仅将它们放置在 WCF 公开的方法上[OperationContract]
解决了该问题。