What are different Transaction Isolation Levels in WCF?

Here, the [Service Behavior] attribute specifies the Transaction Isolation level property. 

Transaction Isolation specifies the degree of isolation most compatible with other applications. 

The data affected by a transaction is called volatile.

There are 5 differenct types of Isolation levels in WCF, as follows-

1. READ UNCOMMITTED : - An uncommitted transaction can be read. This transaction can be rolled back later.

2. READ COMMITTED :- Will not read data of a transaction that has not been committed yet.

3. REPEATABLE READ : - Locks placed on all data and another transaction cannot read.

4. SERIALIZABLE :- Does not allow other transactions to insert or update data until the transaction is complete.

5. SNAPSHOT : - It raises error on modifying a data that has already been changed by any transaction.

What is Transaction in WCF ?

A transaction is a collection or group of one or more units of operation executed as a whole. Another way to say it is that transactions provide a way to logically group single pieces of work and execute them as a single unit, or transaction.

To implement transactions in WCF, we utilize TransactionScope class that automatically manages transactions and detect the scope of the transaction.

For example, if you are calling three services methods and third one fails to complete the operation, transaction will be rolled back unless it’s outside the boundary of a TransactionScope.

WCF supports transaction on following bindings:

1. WSHttpBinding
2. NetTcpBinding
3. NetNamedPipeBinding
4. WSDualHttpBinding
5. WSFederationHttpBinding


When you develop a Service Contract, you have to specify the TransactionFlow attribute on each
Operation Contracts that requires a Transaction to be handled.

There are following flow options in the TransactionFlow attribute.

  1. TransactionFlowOption.Allowed: Transaction can be flowed.
  2. TransactionFlowOption.Mandatory: Transaction must be flowed.
  3. TransactionFlowOption.NotAllowed: Transaction should not be flowed. This is default.

Now, implement the service and specify OperationBehavior attribute on each method. You can specify the TransactionScopeRequired = true / false.

Now enable the Transaction on the binding itself. Open your web.config file and specify the transactionflow = true

Now add service reference and consume the service. In this way you have implemented trasactions for your wcf services.

How to enable Transactions in WCF?


Follow below steps to enable transactions in WCF.

Step 1: Create Two WCF Services 
Step 2: Attribute Interface Methods with TransactionFlow 
Step 3: Attribute the Implementation with TransactionScopeRequired 
Step 4: Enable Transaction Flow using WCF Service Config File 
Step 5: Call the 2 Services in One Transaction and test if Transaction Works.

We will see all these steps in details in later posts.

What are different Transaction Isolation Levels in WCF?

Here, the [Service Behavior] attribute specifies the Transaction Isolation level property.  Transaction Isolation specifies the degr...