Saturday, October 16, 2010

Transactions in WCF: (WCF Part 11)

 

The most important part to understand from my opinion when working with WCF is the transaction part.
A transaction treats a group of operations as an atomic unit, so either all succeed or all fail.

WCF supports two types of transactions: shared transactions and transacted messaging.

WCF supports two transaction protocols:

  1. OleTransaction protocol: Used for transaction control between WCF applications.
  2. WS-AtomicTransaction protocol: Enables WCF applications to flow transactions to interoperable applications, such as Web services that have been built by using third-party technology.

Transaction Process (Client & Server Side)

1-Client Side
Clients use a TransactionScope object to group operations into transactions:

 

[C#]

using (TransactionScope sc = new TransactionScope())

    {

        service1.submitRequest(rq1);

        service2.submitRequest(rq2);

        sc.Complete();

    }

 

As well as specifying transaction requirements, the client can control the isolation level and timeout for the transaction by using a TransactionOptions object:

 

[C#]

TransactionOptions top = new TransactionOptions();

    top.IsolationLevel = IsolationLevel.ReadCommitted;

    using (TransactionScope sc = new TransactionScope(TransactionScopeOption.RequiresNew, top)) //...

 

2-Server Side

The ServiceBehavior attribute enables you to configure the service as a whole for transaction time-outs, isolation level, and whether transactions complete when a session closes.
The OperationBehavior attribute helps you to control whether a transaction is required for an operation, and whether transactions complete if no exception is thrown.


WCF can use Microsoft Message Queuing, or MSMQ, to pass messages between clients and services. Queuing can improve application resilience and scalability.




Reliable Sessions in WCF:

A reliable session provides session-based delivery for WCF messages, regardless of the number or type of transport intermediaries between two endpoints.

Reliable sessions handle lost or duplicated messages. Messages are delivered exactly once, and can optionally be delivered in order. If a message cannot be delivered, the sender is informed.

They are enabled by default for theWsDualHttp, NetNamedPipeandMsmqIntegrationbindings, and can be enabled for theNetTcp, WsHttpandWsHttpFederationbindings.

 



Finally, I’d like to thank all of you for your Attention and hope that you’ve learned something new from these WCF 11 parts that I’ve written :)

Mohamed Adel Mahmoud.
Microsoft Intern – Senior Microsoft Student Partner – Microsoft Egypt.
 
  For More Info Please Visit: WCF Resources Page  

No comments:

Post a Comment

Search This Blog