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.com254 CHAPTER 8 ■ IMPLEMENTING RELIABLE MESSAGING AND QUEUE-BASED COMMUNICATIONSramrameshreddy.blog.comEnabling WCF Web Service with Reliable SessionsAssume you have an interface implemented that is called ITradeService, as shown in Listing 8-1.Listing 8-1. ITradeServiceusing System;using System.Collections.Generic;using System.ServiceModel;using System.Text;namespace QuickReturns{[ServiceContract]public interface ITradeService}{}[OperationContract]string BeginTrade();...void Buy();[OperationContract]void EndTrade();The AddTrade and EndTrade parameters that are provided for the OperationContractattribute ensure that any sequence of invocations to the operation begin with the method andcomplete with the CompleteDeal() method. The client application invokes BeginTrade() andthen invokes AddTrade() twice. It has a Buy() method followed by an EndTrade() method. Let’snow assume that one of the AddTrade() invocations never reached the service. In this case, theservice would still operate in a valid manner, and the application would not miss AddTrade().Similarly, consider the scenario where both the invocations have arrived at the destination.For whatever reason, one of them was delayed and arrived after CompleteDeal() was invoked.The execution sequence would still execute in a valid manner. However, this would not be inthe sequence intended by the client. Overcoming these problems is a fairly simple task.To begin, make the changes shown in Listing 8-2 to ITradeService in order to ensure thatyou do not have a scenario where messages could potentially be received out of order.Listing 8-2. ITradeService Changesramrameshreddyramrameshreddy[ServiceContract(SessionMode=SessionMode.Allowed)]public interface ITradeServiceThis change will ensure that the messages are delivered in the order you intended. That ispractically all you need to do to ensure that you avoid the scenario where messages arereceived out of order.You now need to make the same change to the definition of ITradeService in the client, asshown in Listing 8-3.

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

Saved successfully!

Ooh no, something went wrong!