You are consuming a Windows Communication Foundation (WCF) service.
The service interface is defined as follows:
[DataContract(Namespace = ”]
public class Item
{
}
[ServiceContract(Namespace = ”)]
public interface Catalog
{
[OperationContract]
[WebInvoke(Method=”POST”, UriTemplate=”{Item}”)]
Item UpdateItem(Item item);
}
The client application receives a WebResponse named response with the response from the service.
You need to deserialize this response into a strongly typed object representing the return value of the method.
Which code segment should you use?
A.
DataContractSerializer s = new DataContractSerializer(typeof(Item));
Item item = s.ReadObject(response.GetResponseStream()) as Item;
B.
BinaryFormatter f = new BinaryFormatter();
Item item = f.Deserialize(response.GetResponseStream() as Item;
C.
XmlDictionaryReader r = JsonReaderWriterFactory.CreateJsonReader(response.GetResponseStream(), XmlDictionaryReaderQuotas.Max);
DataContractSerializer s = new DataContractSerializer(typeof(Item));
Item item = s.ReadObject(r) as Item;
D.
DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(Item));
Item item = s.ReadObject(response.GetResponseStream()) as Item;
Explanation:
Use the DataContractSerializer class to serialize and deserialize instances of a type into an XML stream or document.
For example, you can create a type named Person with properties that contain essential data, such as a name and address.
You can then create and manipulate an instance of the Person class and write all of its property values in an XML document for later retrieval,
or in an XML stream for immediate transport. Most important, the DataContractSerializer is used to serialize and deserialize data sent in messages.
Apply the DataContractAttribute attribute to classes, and the DataMemberAttribute attribute to class members to specify properties and fields that are serialized.Serialization and Deserialization
(http://msdn.microsoft.com/en-us/library/ms731073%28v=VS.100%29.aspx)
A