Thursday, 15 September 2011

Transactions In WCF?

Transactions assure that a group of related activity occurs as a single atomic unit.
 In WCF provides a central transaction system that can be used to handle transaction operations.
In order to support transaction the service should first support transactions. Above is a simple code snippet of the server service and client and explanation as below


 1 - At interface level the operationcontract is attributed with [TransactionFlow] attribute.

There are three values for it

1.    Allowed (which mean operation may or may not be used in transaction)
2.    NotAllowed (Where it’s never used in transaction) and
3.    Required (Where the service can only be used in transactions).

 2 - In this section the [ServiceBehavior] attribute specifies the transaction isolation level property.

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



The different levels you can provide in transaction isolation.

Volatile: The data affected by a transaction is called volatile.

Chaos: pending changes from more highly isolated transactions cannot be overridden.

ReadCommitted: - Volatile data can be modified but it cannot be read during the transaction.

ReadUncommitted: - Volatile data can be read as well as modified during the transaction.

RepeatableRead: - Volatile data can be read but not modified during the transaction and also new data can be added.

Serializable: - Volatile data can be only read. But no modifications and adding of new data is allowed.

Snapshot: - Volatile data can be read. But before modifying the data it verifies if any other transaction had changed data. If yes then it raises error. By default, the System.Transactions

3 - This defines the transaction behavior with in the service. [OperationBehavior] has a property called as transactionscope. TransactionScope setting indicates that operation must be called within a transaction scope. You can also see TransactionAutoComplete is set to true which indicates that transaction will complete by default if there are no errors. If you do not provide the TransactionAutoComplete to true thenyou will need to call OperationContext.Current.SetTransactionComplete() to make the transaction complete.



No comments:

Post a Comment

Please Give Your Valuable Comments on this Topic

Archives