TransactionScope across AppDomains and processes
Asked Answered
M

2

5

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

DependentTransaction works only inside one AppDomain.

Moslemism answered 18/3, 2011 at 4:50 Comment(0)
S
8

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();
    }
}
Stowe answered 18/3, 2011 at 5:7 Comment(3)
Could please tell more about the process of passing transaction to another AppDomain? Do you create clone by calling currentTransaction.DependentClone and pass it or just pass current transaction?Moslemism
And what about committing such a transaction? I guess I can commit it only from initial AppDomain?Moslemism
@ldsa: when you pass a Transaction across an appdomain you will be dealing with a distributed transaction. To commit the transaction all participants will have to vote to commit. e.g. appdomain1 and appdomain2 will both have to commit.Stowe
E
0

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 .

Empale answered 27/11, 2012 at 22:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.