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.

CHAPTER 9 ■ USING TRANSACTIONS IN WCF 295ramrameshreddy.blog.comWhen you run the application, you should see that the trades sent by the client show upin the TradeAuditService window and also that the committed trades show up in the window.You have seen how to configure the application to use transactions in conjunction withreliable messaging. You will now learn how to make your queues utilize transactions easily.Working with Transactions and QueuesIn Chapter 8 you saw that MSMQ plays an important part in WCF and offers you a great dealof advantages in terms of reliability in scenarios that require integration with legacy applicationsas well as in scenarios where you require guaranteed delivery.It is important to note that the queuing and dequeuing of messages between a client andthe queue is implicitly transactional. In other words, the transfer of a message to and from aqueue is transactional in nature; either the entire message will get on the queue or no part of itwill be placed on the queue. This is comfortable for scenarios that require one-way messagingonly. However, what if you require a series of operations under the sponsorship of a singletransaction scope?The scenario where you require multiple operations to occur as a single transaction in thecontext of MSMQ is often referred to as a sessiongram, while the single one-way operation isreferred to as a datagram. In using sessiongram scenarios, what you are aiming for is for agroup of operations to occur within the scope of a single transaction exactly once and in order.Open the Chapter09\QueueMessaging solution.■Note In reality, a transaction using message queues requires two transactions. The first transactionoccurs between the application and the queue, and a second occurs between the queue and the receiver. Ifan error occurs in either one of these transactions, the transaction will abort. However, note that the messagessent under the transaction are discarded, while messages received by the queue remain in the queueuntil they are retried at a later time. Transactions using queues provide a level of isolation, inherent reliability,and security. However, for version 1.0 of WCF, they are not interoperable with heterogeneous systems that donot use MSMQ. Technically, you can use IBM MQSeries through the interop mechanism, which you will studyin Chapters 10 and 13.WCF makes programming MSMQ transaction scenarios a lot simpler than you wouldassume, as you will see, in how you configure the audit service and the client parts of yourapplication.Examine QueueMessagingClient shown in Listing 9-13. We have added support for transactionsand are setting a transaction scope.ramrameshreddyramrameshreddyListing 9-13. QuickReturns Ltd. QueueMessagingClientusing System;using System.Transactions;namespace QuickReturns

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

Saved successfully!

Ooh no, something went wrong!