5

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

DependentTransaction works only inside one AppDomain.

SiberianGuy
  • 24,674
  • 56
  • 152
  • 266

2 Answers2

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();
    }
}
Randy Levy
  • 22,566
  • 4
  • 68
  • 94
  • 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? – SiberianGuy Mar 18 '11 at 05:18
  • And what about committing such a transaction? I guess I can commit it only from initial AppDomain? – SiberianGuy Mar 18 '11 at 05:56
  • @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. – Randy Levy Mar 18 '11 at 06:10
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 .

Community
  • 1
  • 1
Todd
  • 530
  • 4
  • 14