How to implement transactions in wcf? [Resolved]

Posted by Programmer123 under WCF on 9/26/2013 | Points: 10 | Views : 2658 | Status : [Member] | Replies : 2
How to implement transactions in wcf? Can any have implemented this?


Posted by: Allemahesh on: 9/27/2013 [Member] [MVP] Silver | Points: 50


You can see the below links:-

Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 9/27/2013 [Member] [MVP] Platinum | Points: 25

If we need to execute two or more SQL commands in such a way that if any one of the statements fails, then no other statement will be able to change the database. So this is the core requirement of transaction to handle this kind of situations.
WCF provides a single unified system for all activities whether it is a database related or not. To use transaction in services the service should support to transactions. WCF transactions uses WS specifications.
To allow transaction in wcf we have to use:
1) Transaction Flow attribute along with contract in our interface
2) You have to set the isolation level property, we have 6 levels of isolation
Chaos: - pending changes from more highly isolated transactions cannot be overridden.
Read Committed: - Volatile data can be modified but it cannot be read during the transaction.
Read Uncommitted:- Volatile data can be read as well as modified during the transaction.
Repeatable Read: - Volatile data can be read but not modified during the transaction and new data can be added.
Serializable: - Volatile data can be only read. However, no modifications and adding of new data is allowed.
Snapshot: - Volatile data can be read. However, before modifying the data it verifies if any other transaction had changed data. If yes then it raises error.
By default, the System. Transactions infrastructure creates Serializable transactions.

Steps: To Create Transactions
In Interface create an operationContract method with the TransactionFlow attribute as
public interface IService{
void UpdateMyData();

Implement the same method in class with TransactionScopeRequired attribute as
[OperationBehavior (TransactionScopeRequired= true)]

public void UpdateMyData()
// your logic
} Then make sure transaction flow is enable in web.config file as
<binding name="MyTransactions" transactionFlow="true"/>
How to Call in Client Program You can commit all wcf transaction with the help of complete method of TransactionScope Object.
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew))

//webservice transactions calls here.. //in below line ts is the object of TransactionScope ts.Complete();
catch (Exception ex)


Mark This Response as Answer

Programmer123, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response