c# - 是否可以在连接到 SQL Azure 数据库的 WCF 服务之间进行分布式事务?

标签 c# wcf azure azure-sql-database

从 .NET Framework 4.6.1 开始 it's possible to have distributed transactions in SQL Azure 。现在,我正在尝试使用 SOA 构建概念验证,因此我尝试创建 TransactionScope 并调用连接到单个 SQL Azure 数据库的几个 WCF 服务,但我在这方面失败了。

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }))
{
    DOConfigurationServiceClient proxy = new DOConfigurationServiceClient();
    proxy.CreateAccessByAccount(accessByAccount);
    scope.Complete();
}

我收到带有以下消息的 System.ServiceModel.ProtocolException:

There is a promotable enlistment for the transaction which has a PromoterType value that is not recognized by System.Transactions. 1c742caf-6680-40ea-9c26-6b6846079764

这是堆栈跟踪

at System.Transactions.InternalTransaction.ThrowIfPromoterTypeIsNotMSDTC()
   at System.Transactions.Transaction.Promote()
   at System.Transactions.TransactionInterop.ConvertToOletxTransaction(Transaction transaction)
   at System.Transactions.TransactionInterop.GetTransmitterPropagationToken(Transaction transaction)
   at System.ServiceModel.Transactions.WsatTransactionFormatter.WriteTransaction(Transaction transaction, Message message)
   at System.ServiceModel.Channels.TransactionChannel`1.WriteTransactionToMessage(Message message, TransactionFlowOption txFlowOption)

是否可以在连接到 SQL Azure 数据库的 WCF 服务之间进行分布式事务?

有关它的文档太少或根本没有,因此我们将非常感谢任何帮助。

最佳答案

简短的回答,不,这不是 SQL Azure 上支持的方案。

WCF 中跨多个服务调用的事务流依赖于分布式事务协调器 (MSDTC) 样式事务的使用。 SQL Azure 特别不支持这些(没有连接到 SQL Azure 的 MSDTC)。

新的 SQL Azure 弹性事务由 SQL 本身管理,而不是由外部事务协调器管理。

一种可能的替代方法是创建一个服务方法来执行您想要封装在事务中的所有操作,并在该服务方法的范围内启动(并完成)事务。

关于c# - 是否可以在连接到 SQL Azure 数据库的 WCF 服务之间进行分布式事务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36640813/

相关文章:

azure - 如何在 Azure 中设置 smtp 服务器

azure - Windows Azure 和传统 Windows 托管有什么区别?

python - 在本地运行使用 Python 创建的 Azure Functions 时出错,Func Start 不会失败

c# - 从 Microsoft UWP 上的异步方法返回 Task<string>

c# - 在 Unity C# 中修复挤压网格法线?

c# - 无法复制文件,即使在 C# 中授予了 FileIOPermission

通过 netTcp 的 WCF 自定义安全性

具有基本身份验证的基于 WCF SSL Rest 的 Web 服务

c# - 断言 C#(社交)单元测试不使用 HTTP

c# - wcf第一次请求很慢?服务解决方案?