Reputation: 602
A client application is calling 2 different WCF services in one TransactionScope, in the hopes of rolling back the entire transaction if one of the calls fails like this:
using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
{
proxy1.UpdateThing(data);
proxy2.UpdateSomeOtherThing(data);
transaction.Complete();
}
Now, the call to proxy1 is fine, but the call to proxy2 throws an exception. Still the call to proxy1 has succeeded when I check the database.
How should I go to work in this scenario? Are DependentTransactions the way to go here?
Both services are hosted on the same machine, both have a wsHttpBinding with TransactionFlow = true. The transaction works for each service in isolation, it's when a call used both services, like in the example, that doesn't work. Both services are decorated with the correct annotations.
The exception is just a hard throw in one of the services, for testing this.
It's worth noting that both services use EF to process their data to the database.
Upvotes: 1
Views: 1368
Reputation: 27944
To enable transactions in WCF you need a lot more as a transaction scope in you consumer.
To add transaction support to a WCF service, you will take the following actions:
To start a transaction in the client application, you must take the following actions:
To read how to implement this you can read (source): Transactions in WCF Services
Upvotes: 2