Flowing or propagating transactions in .Net
System.Transactions transactions are bounded to the appdomain. Which means that if you make in-appdomain calls from inside a TransactionScope, those calls will share the transaction. This also means that if you need to make a call outside the current appdomain, or outside the process, you will need to "flow" the transaction.
To flow a System.Transactions transaction, there are a few options:
a. if you are using serialization
//sender code
using(TransactionScope ts = new TransactionScope())
{
RemoteCallUsingSerialization(Transaction.Current, other parameter); // this is the call to other appdomain/process
// notice I added a new parameter of type System.Transactions.Transaction
ts.Complete();
}
//destination code
void RemoteCallUsingSerialization(System.Transactions.Transaction tx, other parameter)
{
using(TransactionScope ts2 = new TransactionsScope(tx))
{
// access transactional resourses like a database; this code will execute as part of the same transaction
ts2.Complete();
}
}
b. if you are not using serialization
//sender code
using(TransactionScope ts = new TransactionScope())
{
RemoteCall(TransactionInterop.GetTransmitterPropagationToken(Transaction.Current), other parameter); // this is the remote call
// notice I added a new parameter of type byte[]
ts.Complete();
}
//destination code
void RemoteCall(byte[] tx, other parameter)
{
using(TransactionScope ts2 = new TransactionsScope(TransactionInterop.GetTransactionFromTransmitterPropagationToken(tx)))
{
// access transactional resourses like a database;
// this code will execute as part of the same transaction
ts2.Complete();
}
}
c. if .Net 3.0 or higher is an option, you can use WCF and its support for transactions using attributes: https://msdn2.microsoft.com/en-us/library/aa347993.aspx
Remark: When the transaction is flown outside the current appdomain, it will get upgraded to a distributed transaction (or MSDTC transaction).
If you are not using .Net, see https://blogs.msdn.com/florinlazar/archive/2004/10/02/236965.aspx for propagating transactions in C++.