1

下面给出的是我的示例代码。它们都是客户端对服务的同步调用。我的问题是,我的远程服务如何知道调用 -> ts.Complete();

using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew))
{
    try
    {
        ServiceReference1.Service1Client obj = new ServiceReference1.Service1Client();
        obj.UpdateData();
        ServiceReference2.Service1Client obj1 = new ServiceReference2.Service1Client();
        obj1.UpdateData();
        ts.Complete();
    }
    catch (Exception ex)
    {
        ts.Dispose();
    }
}

我正在使用 WSHttpbinding。我的问题是:

  1. WSHttpbinding 和 basicHttpBinding 都支持事务吗?
  2. 在“ts.Complete()”调用期间,或在客户端范围内的异常期间,远程 WCF 服务是否会发生请求调用以使事务管理器提交/回滚他的工作?
4

2 回答 2

2

Will WSHttpbinding and basicHttpBinding both support transactions?

You need to use WSHttpBinding to use TransactionScope as a BasicHttpBinding doesn't support the required WS-* standards for transactions.

During "ts.Complete()" call Or During exception in client scope, will a request call happen to remote wcf service to make the transaction manager commit/rollback his job

The complete call doesn't guarantee everything is committed. This tells the transaction manager you are done. It is the complete call on the transaction owner that causes the transaction manager to inform all parties to commit or rollback. If it can't communicate with all parties, it will throw an exception.

So to answer the question, the complete call on child-participants (i.e. not the owner) don't cause a call to the transaction manager, but the complete call from the owner-participant does call the transaction manager, which will then attempt to commit.

于 2013-01-28T16:56:17.120 回答
1

TransactionScope 使用 MSDTC :

MSDTC 是 Microsoft 分布式事务协调器的首字母缩写词。顾名思义,MSDTC 是一种为分布式系统提供事务基础设施的 Windows 服务。在这种情况下,事务意味着构建分布式系统中自治代理之间交互的一般方式。每个事务都是具有四个关键属性的状态转换 - ACID 属性:原子(全有或全无)、一致(合法)、隔离(独立于并发事务)和持久(一旦发生,就不能被废除)。有不同的技术可以实现 ACID 属性,但最著名的一种是两阶段提交。

您应该从这篇文章开始:http: //blogs.msdn.com/b/florinlazar/archive/2004/03/04/what-is-msdtc-and-why-do-i-need-to-care-about -it.aspx

于 2013-01-28T10:50:19.017 回答