在 TransactionScope 内使用 netMsmqBinding 调用 WCF 停止事务

发布于 2024-08-07 00:34:27 字数 318 浏览 8 评论 0原文

我有一个通过 MSMQ 运行的 WCF 日志记录服务。项目被记录到 Sql Server 2005 数据库中。如果在 TransactionScope 之外使用,每个功能都会正常运行。当在 TransactionScope 实例内部使用时,该调用始终会导致事务中止。消息 =“事务已中止”。

我需要做什么才能让这个调用在事务中工作?有可能吗?我读到,对于跨服务边界的客户端事务,绑定必须支持事务流,这会立即将绑定限制为仅 NetNamedPipeBinding、NetTcpBinding、WSHttpBinding、WSDualHttpBinding 和 WSFederationHttpBinding。

I have a WCF logging service that runs operates over MSMQ. Items are logged to a Sql Server 2005 database. Every functions correctly if used outside a TransactionScope. When used inside a TransactionScope instance the call always causes the transaction to be aborted. Message = "The transaction has aborted".

What do I need to do to get this call to work inside a Transaction? Is it even possible. I've read that for a client transaction to flow across a service boundary the binding must support transaction flow, which immediately limits the bindings to only NetNamedPipeBinding, NetTcpBinding, WSHttpBinding, WSDualHttpBinding and WSFederationHttpBinding.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

山有枢 2024-08-14 00:34:27

我对 MSMQ 不是很了解,但是 Tom Hollander 在 MSMQ、IIS 和 WCF:让它们发挥出色 - 第 3 部分,这是链接如果汤姆谈论如何进行交易。

MSMQ 可以是事务性的,也可以不是。在 WCF 中,您可以使用与事务相关的属性(例如是否允许、禁止或需要事务上下文)来装饰服务契约以及各个操作契约(方法)。

据我了解,在您的设置中,您不希望 MSMQ 部分是事务性的 - 但即使存在环境事务,您也应该能够使用它。在这种情况下,您需要将 TransactionFlow="ALlowed" 添加到您的操作合约中,如下所示:

[ServiceContract]
public interface ILoggingService
{
  [OperationContract]
  [TransactionFlow(TransactionFlowOption.Allowed)]
  void LogData(......);
}

应该可以了!

马克

I'm not intimately knowledgeable about MSMQ, but there's a really good blog post series by Tom Hollander on MSMQ, IIS and WCF: Getting them to play nicely - in part 3 which is the link provided Tom talks about getting transactional.

MSMQ can be transactional - or not. And in WCF, you can decorate both the service contract as well as individual operation contracts (methods) with transaction-related attributes, such as whether to allow, disallow, or require a transaction context.

As far as I understand, in your setup, you don't want the MSMQ part to be transactional - but you should be able to use it even if an ambient transaction is present. In this case, you need to add the TransactionFlow="ALlowed" to your operation contract like this:

[ServiceContract]
public interface ILoggingService
{
  [OperationContract]
  [TransactionFlow(TransactionFlowOption.Allowed)]
  void LogData(......);
}

That should do it!

Marc

心在旅行 2024-08-14 00:34:27

抱歉提出了不必要的问题...

我已经解决了我的问题。我需要将

[TransactionFlow(TransactionFlowOption.Allowed)]

操作放在服务合同中,然后

[OperationBehavior(TransactionScopeRequired=true)] 

放在合同(服务本身)的实施上。

工作是一种享受。

Sorry for the needless question...

I have solved my problem. I needed to place

[TransactionFlow(TransactionFlowOption.Allowed)]

on the operation in the service contract and then

[OperationBehavior(TransactionScopeRequired=true)] 

on the implementation of the contract (the service itself).

Works a treat.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文