在 TransactionScope 内使用 netMsmqBinding 调用 WCF 停止事务
我有一个通过 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对 MSMQ 不是很了解,但是 Tom Hollander 在 MSMQ、IIS 和 WCF:让它们发挥出色 - 第 3 部分,这是链接如果汤姆谈论如何进行交易。
MSMQ 可以是事务性的,也可以不是。在 WCF 中,您可以使用与事务相关的属性(例如是否允许、禁止或需要事务上下文)来装饰服务契约以及各个操作契约(方法)。
据我了解,在您的设置中,您不希望 MSMQ 部分是事务性的 - 但即使存在环境事务,您也应该能够使用它。在这种情况下,您需要将 TransactionFlow="ALlowed" 添加到您的操作合约中,如下所示:
应该可以了!
马克
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:
That should do it!
Marc
抱歉提出了不必要的问题...
我已经解决了我的问题。我需要将
操作放在服务合同中,然后
放在合同(服务本身)的实施上。
工作是一种享受。
Sorry for the needless question...
I have solved my problem. I needed to place
on the operation in the service contract and then
on the implementation of the contract (the service itself).
Works a treat.