11.07.2015 Views

y - Net Developer

y - Net Developer

y - Net Developer

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

amrameshreddy.blog.com278 CHAPTER 9 ■ USING TRANSACTIONS IN WCFramrameshreddy.blog.comWhat’s a Transaction?What is a transaction? Broadly speaking, a transaction is a mechanism to ensure that severaloperations succeed or fail as an atomic unit. In other words, it ensures that all operationssucceed or all operations fail in the event that even one of the constituent components of thetransaction encounters an error. Broadly speaking, transactions enforce the ACID rule popularizedin database programming. WCF provides a simple centralized manner to supporttransactions within your applications. Prior to WCF, although there were mechanisms tosupport transactions (Begin Transaction...End Transaction in Visual Basic, for example), asingle standard means of being able to support nondatabase transactions was not a trivial taskto say the least. A transaction enables you to carry out a set of operations as a single executionunit whereby you achieve reliable results.In the QuickReturns Ltd. scenario, you conduct trades on the stock exchange, and notknowing for sure whether a trade was successful could have disastrous results. Using thetransaction mechanism, you achieve the following results:Atomicity: The trades go through the system as single unit, thus achieving durability oraborting as a single unit, where nothing goes through in a rollback of the transaction.Consistency: This guarantees that the transaction is a correct transformation in the systemstate. All orders that are part of a single transaction do so with the correct attributes(buy/sell, associated quantities/prices), and that behavior is repeatable identically timeafter time.Isolation: This ensures that each transaction is independent and isolated from othertransactions that could be occurring simultaneously in the system. The transactions donot have any impact on the behavior of any other transaction that might be occurring inthe system. Looking at the trade system, it is more than likely that more than one user isusing the system to trade at the same time. The isolation of the transactions ensures thatthe trades conducted by other users, or even multiple trades occurring at the same timefrom a single user, are treated as being distinct and separate from each other.Durability: As the name suggests, this ensures that all data is committed to a nonvolatileresource such as a database, an XML file, or even a flat file. The data of the transactionmust remain available even though the transaction has long since completed. For us, thisprovides a record for the trades provided. You can check when a particular trade was conductedand have the data available to you whenever you want it.WCF implements the WS-Atomic protocol to enable transaction support. This enablesyou to build transactions that can interact with multiple endpoints inside WCF and with thirdpartysystems such as web services.A transaction has multiple discrete players involved in the process. These componentsinteract with each other and are essential for any given transaction. If you consider Figure 9-1,you can see that any transaction has three essential components: the application, the persistentstore, and the transaction manager.ramrameshreddyramrameshreddy

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!