Why TransactionScope in WCF?

By Perry

I was really wondering why we need TransactionScope at all. Then I found very valid reason that I have posted here for other people.

Flowing transactions is used when an operation in service A needs to rollback if an operation in service B executed in the same scope fails.

Scenario:

We have 3 services: DebitService, CreditService and AccountManager. We implement an operation to transfer money from account 123 to account 456. In the implementation of Transfer in AccountManager, DebitService is called to take a sum of money from account 123 and CreditService is called to add that same sum of money to account 456. These operation are called in a transaction scope so that if the call to DebitService fails, then the sum of money taken from account 123 by DebitService is rollback as if nothing happened.

You can see http://www.eggheadcafe.com/community/aspnet/18/10168462/re-why-do-we-need-flowed.aspx for other details.

Why TransactionScope in WCF?  (1526 Views)