Which code segment should you use?

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 ICatalog { [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?

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 ICatalog { [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.
Item item = f.Deserialize(response.GetResponseStream()) as Item; XmlDictionaryReader
r = JsonReaderWriterFactory.CreateJsonReader( response.GetResponseStream(),
XmlDictionaryReaderQuotas.Max);

B.
DataContractSerializer s = new DataContractSerializer(typeof(Item)); Item item =
s.ReadObject(r) as Item;

C.
DataContractSerializer s = new DataContractSerializer(typeof(Item)); Item item =
s.ReadObject(response.GetResponseStream()) as Item; BinaryFormatter f = new
BinaryFormatter();

D.
DataContractJsonSerializer s = new DataContractJsonSerializer(typeof(Item)); Item item
= s.ReadObject(response.GetResponseStream()) as Item;



Leave a Reply 0

Your email address will not be published. Required fields are marked *