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 65ramrameshreddy.blog.comIsRequired: Gets or sets a value that instructs the serialization engine that the membermust be present.Order: Gets or sets the order of serialization and deserialization of a member. This can beimportant if clients rely on the order of the fields.EmitDefaultValue: Gets or sets a value that specifies whether to generate a default value ofnull or 0 for a field or property being serialized.Message ContractsSometimes you require more control over the SOAP envelope that WCF generates. For example,you may want to be able to map fields in your message to the SOAP headers instead of theSOAP body. This is when message contracts come into play. The [MessageContract] attributeallows you to map fields into either the SOAP body or the SOAP headers by means of the[MessageBody] and [MessageHeader] attributes, as shown in Listing 3-4.Listing 3-4. Quote as a MessageContractusing System;using System.ServiceModel;namespace QuickReturns.StockTrading.ExchangeService.MessageContracts{[MessageContract]public class QuoteMessage{[MessageBody]public string Ticker;}}[MessageBody]public decimal Bid;[MessageBody]public decimal Ask;[MessageHeader]public string Publisher;[MessageBody]private DateTime UpdateDateTime;ramrameshreddyramrameshreddyIn this example, the publisher has now moved from the SOAP body to the SOAP headers.Now you can use this message contract in an operation contract, just like you did with thedata contract. So when you need direct control over the SOAP envelope, you can use messagecontracts to control how properties of your types map to the SOAP headers and SOAP body.

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

Saved successfully!

Ooh no, something went wrong!