Reputation: 529
I read about the wcf transactions but not able to find out its use. Does anybody know any scenario where we should use wcf transaction. Realtime example would be helpful to understand.
Upvotes: 2
Views: 339
Reputation: 2666
A WCF Transaction allow us to make operations that consumers can use inside transactions. We can call a wcf service operation inside a transaction scope (for example) and ensure that our operation will be atomic. It's really helpful to ensure integrity in our operations.
For example, suppose that we have two wcf operations:
If I've implemented wcf transactions I can build up a transfer operation mixing the two operations in a transaction and I'll be sure that there will not be any inconsistency. If any of service calls fail , the entire transaction will rollback.
try
{
using(TransactionScope scope = new TransactionScope())
{
IserviceClient client = new IserviceClient();
client.debit(499,"acdf5-sdsd-4546-223-2");
client.deposit(499,"45651-as4d-ghhd-222-1");
scope.Complete();
}
}
catch
{
Debug.WriteLine("Some error occurred...");
}
It can be helpful. http://www.codeproject.com/Articles/183708/WCF-Transactions-Brief-Introduction
EDIT: You should use transactions when the service operation changes any state (a database insert,update or delete, any file modification) although transactions are not useful when you do a simple read operation for example.
Upvotes: 1