Using Transactions in WCF

Transactions are fundamental to applications in order to ensure consistent behavior for data. In addition, they are a fundamental building block for ensuring the implementation of atomic, consistent, independent, and durable (ACID) behavior in an application. In the QuickReturns Ltd. application, ACID behavior means that when you do make a trade, it is absolute. It will either be complete in its entirety or be rolled back, leaving no room for ambiguity. If you were to put in a buy order for a stock, you would definitely want to be sure that the trade were absolute, right? Without transactions, you would not be sure that the trade was indeed conducted, and you would have no means of verifying the validity without ambiguity. Having a transactional system ensures that trades are consistently applied and are final. After all, you want to be clear about whether a trade has actually occurred.

You need to ensure that the systems being built provide you with features such as recoverability. That is, if a service or machine fails, when it does come back, data is still available. Scalability is another area where transactions are critical, since it clearly earmarks the point at which resources are requested and released at the end of the transaction. This enables you to avoid deadlocks, whereby two or more threads are trying to acquire the same resources, causing the application to hang. Typically deadlocks are resolved by making one of the threads release its resources. Transactions are critical in this to ensure safe system state and to ensure that any data that was being applied is rolled back successfully. Finally, transactions are important to preserve data integrity. (In other words, when you perform the same query to your persistent data store, you want to receive the same result each time.) Transactions are the basis of ensuring this. These are key business drivers for transactional support in any enterprise application.

WCF provides rich support for transactions, and you will look at that support in detail in this chapter. Specifically, we will cover the following topics:

  • The need for transactions

  • The types of transactions in WCF

  • How to define transactions in WCF

  • How to use transactions with queues

This chapter builds on the concepts introduced in Chapter 8; it is important that you are familiar with those concepts, since they really do go hand in hand with each other.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset