从 .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/