11.07.2015 Views

y - Net Developer

y - Net Developer

y - Net Developer

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 11 ■ WORKING WITH DATA 349ramrameshreddy.blog.comOne caveat to using the round-tripping feature is that sometimes it may cause the WCFruntime to produce schema-invalid messages. Round-tripping should be disabled when strictschema compliance is a requirement, such as if a future version of a data contract adds newmembers. When serialized, these new members are stored in the ExtensionData property.Now, when this new data contract is serialized the next time, the ExtensionData property willbe serialized instead of the content of that ExtensionData property (that is, the new members).This will result in a message with a schema in which the new members are not present.If at some point in the future you do not like the support for unknown members and wantto switch off round-tripping, you can do so quite easily. For example, you might have a requirementfor strict schema compliance in the future. You can disable this feature by setting theIgnoreExtensionDataObject property in the [ServiceBehavior] attribute to true. Listing 11-7shows how you can apply this at the service level. The class called Main implements a servicedefined by the interface IQuickReturnTraderChat.Listing 11-7. Sample Showing How to Ignore ExtensionDataObject at a Service Level[ServiceBehavior(InstanceContextMode =InstanceContextMode.Single,IgnoreExtensionDataObject=true)]public partial class Main : Form, IQuickReturnTraderChat{//Code removed for clarity}If you want to implement certain behaviors at an operation level as opposed to theservice level, then use the [OperationBehavior] attribute instead of the [ServiceBehavior]attribute. However, the [OperationBehavior] attribute supports only a subset of features ofthe [ServiceBehavior] attribute.■Note The [ServiceBehavior] attribute specifies the internal execution behavior of a specific serviceand applies at the service-wide level, affecting all the operations within that service. You can use this attributeto enable most common features such as concurrency, exception details, automation session shutdown,transaction behavior, and so on, which otherwise would need to be manually implemented.XML SerializationramrameshreddyramrameshreddyAs you have seen so far, the default option to serialize data types is the data contractserializer, which is implemented via the DataContractSerializer class. However, WCFalso supports XmlSerializer. Although XmlSerializer supports fewer types compared toDataContractSerializer, it does provide better control over the resulting XML and also supportsmore of the XSD standard. Even though DataContractSerializer is the default option,sometimes using XmlSerializer is better:

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

Saved successfully!

Ooh no, something went wrong!