PrepAway - Latest Free Exam Questions & Answers

Which interface should you implement in the data contract class?

You are developing a data contract for a Windows Communication Foundation (WCF) service.
The data in the data contract must participate in round trips. Strict schema validity is not required.
You need to ensure that the contract is forward-compatible and allows new data members to be added to it.
Which interface should you implement in the data contract class?

PrepAway - Latest Free Exam Questions & Answers

A.
ICommunicationObject

B.
IExtension<T>

C.
IExtensibleObject<T>

D.
IExtensibleDataObject

Explanation:
IExtensibleDataObject Interface Provides a data structure to store extra data encountered by the XmlObjectSerializer
during deserialization of a type marked with the DataContractAttribute attribute.

The IExtensibleDataObject interface provides a single property that sets or returns a structure used to store data
that is external to a data contract. The extra data is stored in an instance of the ExtensionDataObject class and
accessed through the ExtensionData property. In a roundtrip operation where data is received, processed, and sent back,
the extra data is sent back to the original sender intact. This is useful to store data received from future versions of the contract.
If you do not implement the interface, any extra data is ignored and discarded during a roundtrip operation.

IExtensibleDataObject Interface
(http://msdn.microsoft.com/en-us/library/system.runtime.serialization.iextensibledataobject.aspx)

// Implement the IExtensibleDataObject interface to store the extra data for future versions.
[DataContract(Name = “Person”, Namespace = “http://www.cohowinery.com/employees”)]
class Person : IExtensibleDataObject
{
// To implement the IExtensibleDataObject interface,
// you must implement the ExtensionData property. The property
// holds data from future versions of the class for backward compatibility.
private ExtensionDataObject extensionDataObject_value;
public ExtensionDataObject ExtensionData
{
get
{
return extensionDataObject_value;
}
set
{
extensionDataObject_value = value;
}
}
[DataMember]
public string Name;
}

Forward-Compatible Data Contracts
(http://msdn.microsoft.com/en-us/library/ms731083.aspx)

One Comment on “Which interface should you implement in the data contract class?


Leave a Reply