Search content within the blog

Tuesday, August 10, 2010

Implementing transactions in WCF part - II

Flowing Transactions Across Operations
In part - I we saw how transactions can be implemented if the scope of the call is within the same service. However if a call requires that a transaction is completed only if calls to two different services succeeds requires a little extra config and code changes which are explained below.

When working with distributed systems, transactions sometimes must span service boundaries. For instance, if one service managed customer information and another service managed orders, and a user wanted to place an order and ship the product to a new address, the system would need to invoke operations on each service. If the transaction completed, the user would expect that both systems were properly updated.
If infrastructure supports an atomic transactional protocol, the services can be composed into an aggregate transaction as just described. WS-AT (Web Service Atomic Transactions) provides the infrastructure for sharing information among participating services to implement the two-phase commit semantics necessary for ACID transactions. In WCF, flowing transactional information across service boundaries is referred to as transaction flow.To flow transactional semantics across service boundaries, the following five steps must be taken:

Service contracts must require sessions because this is how information will be shared
between the coordinator (typically the client) and the participating services.

(Operation Behavior)TransactionScopeRequired = true.
Operation behavior must require a transaction scope. This will create a
new transaction if one is not already present.

(Operation Behavior)TransactionFlowOption.Allowed
Operation contracts must allow transaction information to flow in the header of messages.

(Binding Definition)TransactionFlow = true.
The binding must enable transaction flow so that the channel can put transaction information into the SOAP header. Also note that the binding must support
sessions because wsHttpBinding does and basicHttpBinding does not.

The party that initiates the transaction,
typically the client, must use a transaction scope when calling the
service operations. It must also call TransactionScope.close()to commit the changes.

No comments:

Post a Comment