You are creating a Windows Communication Foundation service by using Microsoft .NET Framework 3.5. The service has an operation contract named GetMessage. You write the following code segment to implement the service. (Line numbers are included for reference only.)
01 public Message GetMessage()
02 {
03 Message msg=null;
04 string action=”GetMessageResponse”;
05 MessageVersion ver=MessageVersion.Default;
06 FileStream stream=new FileStream(@”D:\File.xml”, 07 FileMode.OpenOrCreate);
08
09 return msg;
10 }
You need to send the contents of the File.xml file to a client application by using the SOAP body.
Which code segment should you insert at line 08?
A.
msg=Message.CreateMessage(ver, action, stream);
B.
XmlReader reader=XmlReader.Create(stream);
msg=Message.CreateMessage(ver, action, reader);
C.
XmlWriter writer=XmlWriter.Create(stream);
msg=Message.CreateMessage(ver, action, writer);
D.
XmlObjectSerializer ser=new DataContractSerializer(typeof(XmlDocument));
msg=Message.CreateMessage(ver, action, stream, ser);
Explanation:
There is no method overload which accepts an XmlWriter as a parameter for Message.CreateMessage, therefore, the answer choice must be B.
http://msdn.microsoft.com/en-us/library/ms734675.aspx