具有事务支持的 WCF 自定义消息编写

发布于 2024-09-16 05:55:28 字数 502 浏览 3 评论 0原文

我正在使用继承 System.Servicemodel.Channels.Message 的自定义消息。
我的自定义消息获取从数据库中提取的 IEnumerable 集合。
WCF 服务是事务性的(已经过测试)。

MS-DTC 已启用。

问题是,当在自定义消息中执行 protected override void OnWriteBodyContents(XmlDictionaryWriter writer) 方法时,没有事务。
System.Transactions.Transaction.Current 为空。在执行服务时,事务流工作正常,但是当消息由 WCF 机制写入时,它似乎脱离了事务,导致(拉取数据的)数据库命令在没有事务的情况下执行。
请注意,如果我传递简单数组而不是 IEnumerable,则数据库操作将在事务下执行,但我希望它与响应写入并行执行。

请问有什么想法吗,为什么交易丢失以及可以做什么来激活它?

非常感谢!
塔米尔.

I'm using a custom message that inherits the System.Servicemodel.Channels.Message.
My custom message get IEnumerable collection which pulled from a database.
The WCF service is transactional (which is already tested).

MS-DTC is enabled.

Problem is, that when the protected override void OnWriteBodyContents(XmlDictionaryWriter writer) method is executed at the custom message, there is no transaction.
The System.Transactions.Transaction.Current is null. while executing the service the transaction flow is works fine, but when the message is written by WCF mechanism, it's seems like it's out of a transaction which cause the DB command (of pulling the data) to be executed without transaction.
Please note, that if I'm passing simple array instead of IEnumerable the DB action is executed under transaction, but I want it to be executed parallelly with the response writing.

Any ideas please, why the transaction is missing and what can be done to activate it?

many thanks!
Tamir.

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

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

发布评论

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

评论(1

喜爱皱眉﹌ 2024-09-23 05:55:28

事务通常附加到当前线程或调用上下文。因此,如果您在不同的线程上启动事务,并且消息序列化发生在另一个线程上,则事务将在该线程上不可用。您应该查看 TransactionScope 和 DependentTransaction 以支持此类场景。

Transaction are generally attached to your current thread or calling context. So if you are initiating transaction on different thread and message serialization is happing on another thread then transaction won't be available on that thread. You should look at TransactionScope and DependentTransaction for supporting such scenarios.

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