Skip to Content
Programming WCF Services, 2nd Edition
book

Programming WCF Services, 2nd Edition

by Juval Lowy
November 2008
Intermediate to advanced
784 pages
23h 28m
English
O'Reilly Media, Inc.
Content preview from Programming WCF Services, 2nd Edition

The Transaction Class

The Transaction class from the System.Transactions namespace, introduced in .NET 2.0, represents the transaction that all WCF transaction managers work with:

[Serializable]
public class Transaction : IDisposable,ISerializable
{
   public static Transaction Current
   {get;set;}

   public void Rollback(  ); //Abort the transaction
   public void Dispose(  );

   //More members
}

Developers rarely need to interact with the Transaction class directly. The main use of the Transaction class is to manually abort a transaction by calling the Rollback( ) method. Additional features of the Transaction class include enlisting resource managers, setting the isolation level, subscribing to transaction events, cloning the transaction for concurrent threads, and obtaining the transaction status and other information.

The Ambient Transaction

.NET 2.0 defined a concept called the ambient transaction, which is the transaction in which your code executes. To obtain a reference to the ambient transaction, call the static Current property of Transaction:

Transaction ambientTransaction = Transaction.Current;

If there is no ambient transaction, Current will return null. Every piece of code, be it client or service, can always reach out for its ambient transaction. The ambient transaction object is stored in the thread local storage (TLS). As a result, when the thread winds its way across multiple objects and methods on the same call chain, all objects and methods can access their ambient transactions. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming WCF Services

Programming WCF Services

Juval Lowy

Publisher Resources

ISBN: 9780596157210Supplemental ContentErrata