24 March 2014

Transaction Propagation

         In WCF, transaction can be propagated across service boundary. This enables service to participate in a client transaction and it includes multiple services in same transaction, Client itself will act as service or client.
         
        We can specify whether or not client transaction is propagated to service by changing Binding and operational contract configuration

<Bindings>
      <NetTcpBinding>
        <binding transaction Flow="true"></binding>
      </ NetTcpBinding >
    </ Bindings>

Even after enabling transaction flow does not mean that the service wants to use the client’s transaction in every operation. We need to specify the “TransactionFlowAttribute” in operational contract to enable transaction flow.

[Service Contract]
Public interface IService
{
    [Operation Contract]
    [TransactionFlow(TransactionFlowOption.Allowed)]
    Int Add (int a, int b);
    [Operation Contract]
    Int Subtract (int a, int b);
}

Note: TransactionFlow can be enabled only at the operation level not at the service level.


TransactionFlow
Option
Binding configuration

NotAllowed
transaction Flow="true"
or
transaction Flow="false"
Client cannot propagate its transaction to service even client has transaction
Allowed
transactionFlow="true"
Service will allow to flow client transaction.
It is not necessary that service to use client transaction.
Allowed
transactionFlow="false"
If service disallows at binding level, client also should disable at binding level else error will be occurred.
Mandatory
transactionFlow="true"
Both Service and client must use transaction aware binding
Mandatory
transactionFlow="false"
InvalidOperationException will be throw when service binding disables at binding level.
Fault Exception will be thrown when client disable at its binding level.


 




No comments:

Post a Comment