开发者

TransactionScope across AppDomains and processes

开发者 https://www.devze.com 2023-02-18 09:36 出处:网络
Is it real to use System.Transactions (primarily TransactionScope) across different AppDomains and processes?

Is it real to use System.Transactions (primarily TransactionScope) across different AppDomains and processes?

DependentTra开发者_JAVA技巧nsaction works only inside one AppDomain.


Yes, it works. We are flowing transactions via WCF, calling out of process transactional COM+ components, and manually passing transactions from a .NET 2.0 asmx web service to a WCF service.

Now that is not to say that the setup is not finicky. I think most of the issues were around getting MSDTC set up properly on all the servers.

UPDATE

We don't use DependentClone. We are passing the transaction as a byte array using GetTransactionFromTransmitterPropagationToken. Very similar to the second example of Propagating a Transaction Across AppDomains.

As an example:

Client:

public void CallOutOfProcessAndPassTransaction
{
    Client client = new Client();

    client.DoSomethingTransactional(
        System.Transactions.TransactionInterop.GetTransmitterPropagationToken(
            System.Transactions.Transaction.Current)
    );
}

Service:

public void DoSomethingTransactional(byte[] tx)
{
    using (TransactionScope ts = new TransactionScope(
               TransactionInterop.GetTransactionFromTransmitterPropagationToken(tx)))
    {
        // Do Something

        // vote to commit the transaction if the caller also agrees
        ts.Complete();
    }
}


I found problems with this style of solution. In my case I was doing work in the parent and multiple children. To get it to work I had to use TransactionScope only in the parent. My own question/answer are at Using transactions across processes .

0

精彩评论

暂无评论...
验证码 换一张
取 消