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 3 ■ EXPLORING THE WCF PROGRAMMING MODEL 61ramrameshreddy.blog.comListing 3-1. ServiceContract for the Trade Serviceusing System.ServiceModel;using QuickReturns.StockTrading.ExchangeService.DataContracts;namespace QuickReturns.StockTrading.ExchangeService.Contracts{[ServiceContract(Namespace = "http://QuickReturns")]interface ITradeService{[OperationContract()]Quote GetQuote(string ticker);}}[OperationContract()]void PublishQuote(Quote quote);This service is the exchange of the stock-trading application for QuickReturns Ltd. Thecontract of this service defines the interaction that is going on between the sellers and buyerson a stock market. Sellers offer their stocks by publishing quotes. A quote obviously defines thecompany the stock is for and what price the seller wants to have for it. Hence, the PublishQuotemethod is able to publish quotes by sellers on the trade service. The buyers, on the other hand,will query the trade service to get a quote on a specific type of stock for a specific company.Therefore, the GetQuote method is able to retrieve published quotes from the service. When thebuyer finds an appropriate seller, the actual exchange of stocks can take place by a differentservice (which will be covered later in this book).As you can see, the exchange service is marked with the [ServiceContract] attributeand currently has two operations, GetQuote and PublishQuote. These operations have the[OperationContract] attribute applied. WCF uses these attributes to determine which .NETmethods it needs to invoke based on an incoming SOAP message. The attributes also determinethe serialization WCF has to do for you. WCF serialization encompasses the mappingfrom SOAP messages to your .NET objects. In Listing 3-1, Quote is a custom .NET type whereno mapping is defined yet. For the custom Quote object and any other custom object you wantto pass between services and clients, you have to define data contracts. Data contracts controlthe mapping between SOAP messages and .NET objects. We’ll cover data contracts in the nextsection.To influence the service contract, the [ServiceContract] attribute has several parametersthat have their own functions:CallbackContract: Gets or sets the type of callback contract. This is useful when using theduplex messaging exchange pattern.ramrameshreddyramrameshreddyConfigurationName: Defines the name as used in the configuration file to store the relatedconfiguration settings.Name: Gets or sets the name for the element in WSDL. The default value is thename of the .NET interface.

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

Saved successfully!

Ooh no, something went wrong!