Introduction and Goal
This is my 5th WCF FAQ article. This article is completely dedicated to WCF transactions. In this article we will understand the WCF transaction protocol, two phases in WCF transaction, transaction options and finally end up with simple sample for WCF transaction.
Watch my 500 videos on Azure, WCF, WPF, LINQ, Design patterns, WWF, Silverlight, UML @ http://www.questpond.com/
WCF is new to me I am not in a position to read this article?
If you are completely new to WCF then this article will not suffice, my suggestion would be to go through some of the below articles for basics.
WCF FAQ Part 1 - This is a 20 question FAQ for beginners which explains basic concepts of WCF like End points, contracts, and bindings. It also discusses various hosting methodologies of WCF service. The article finally ends talking about bindings and one ways operations in WCF.
WCF FAQ Part 2 - This FAQ covers 10 questions which talks about concepts like duplex contracts , hosting WCF on different protocols, MSMQ bindings, transaction isolation levels, and two way communication. The article finally ends talking about two queues volatile and dead letter queue.
WCF FAQ Part 3 ( Security FAQ ) - In this article, we will start with transport and message security understanding. We will then see simple code samples of how to implement transport and message security using WsHTTP bindings. We will also see what is the difference between 'BasicHttpBinding' and 'WsHttpBinding' with the help of a simple source code. WCF security is a huge topic by itself, but we are sure with this article you will get a quick start of how to go about WCF security.
WCF Tracing FAQ part 4 - In this article, we will look how we can trace and debug information in WCF services. There are some ready made tracelisteners provided by WCF. The base of these ready made trace listeners is .NET trace listener. So we will first understand the basic concept of trace listener and then go through the ready made tracelisteners provided by WCF.
Which protocol is used to handle transactions in WCF?
WCF follows WS-* specifications. So it uses WS-Atomic protocol to managed transaction across WCF services. So you can have different WCF services hosted on different computers and they all can run under one transaction unit. The best part of WS-Atomic protocol is that in one transaction you can have heterogeneous WCF services developed in different platform. In other words you can have JAVA and .NET web services running under one transaction. WS-* specifications are globally approved standards to create services.
What are the two different kinds of phases in WCF transactions?
WCF transactions follow 2 phase commit. So there are 2 phases one is the prepare phase and the other is the commit phase. All co-ordination of transactions is done by the transaction manager.
In prepare phase the transaction manager checks whether all entities are prepared to commit. In commit phase the actual commit starts. You can think about prepare phase as a check saying that all entities are ready to commit and in the commit phase we do the actual work.
Where does the transaction manager reside?
Transaction manager resides at the client computer who initiates the transaction.
Can you explain in depth how prepare and commit phases work?
Let's consider 3 computers as shown in the below figure. The client consuming the WCF service resides in computer 'A' while computer 'B' and 'C' have the WCF services. The transaction is initiated from the computer 'A'. So as we said previously there are 2 phase one is the prepare phase and the other commit phase. In prepare phase computer 'A' sends messages to all the WCF services saying, are they ready to commit?. Once all WCF services respond saying that they are ready for commit it starts the second phase i.e. In the second phase the WCF client issues a commit command. All the WCF services start execution and once they are done they revert back saying they have committed. When all the WCF services revert saying they have committed the transaction is marked as successful.
Can we implement transactions in one-way WCF service calls?
As we have already seen in the previous questions that WCF transactions are 2-phase commits. In other words for every commit you need to get a confirmation response, saying is the commit successful. In one-way WCF services we do not get any response back , so WCF transactions are not possible with 1 way WCF service calls.
Can we see simple WCF example of transactions using SQL Server database?
To enable WCF transaction is a 6 step procedure. So let's create two WCF services and let's try to call them in one transaction.
Step 1 - Create two WCF service
The first step is to create two WCF service projects which will participate in one transaction. In both of these WCF services we will do database transactions and we will try to understand how a WCF transaction unifies them. We have also created a web application with name 'WCFTransactions' which will consume both the service in one transaction scope.
Step 2 - Attribute interface methods with TransactionFlow

Rajesh KumarPosted Dec 4, 2014, 6:31 AM
good
Vithal WadjePosted Sep 24, 2014, 11:07 AM
great
stav alfiPosted Apr 22, 2012, 2:37 PM
it isnt working!!!! http://stackoverflow.com/questions/10270729/wcf-transactionscope-doesnt-rollback what am I doing not good?
Hemant kumarPosted Feb 24, 2011, 10:50 AM
Great!!