Which code segment should you insert at line 12?

You are developing a Windows Communication Foundation (WCF) service.
The following code defines and implements the service. (Line numbers are included for reference only.)

01 [ServiceContract(SessionMode = SessionMode.Allowed)]
02 public interface ICatchAll
03 {
04 [OperationContract(IsOneWay = false, Action = “*”, ReplyAction = “*”)]
05 Message ProcessMessage(Message message);
06 }
07
08 public class CatchAllService : ICatchAll
09 {
10 public Message ProcessMessage(Message message)
11 {
12
13 …
14 return returnMsg;
15 }
16 }

You need to ensure that two identical copies of the received message are created in the service.
Which code segment should you insert at line 12?

You are developing a Windows Communication Foundation (WCF) service.
The following code defines and implements the service. (Line numbers are included for reference only.)

01 [ServiceContract(SessionMode = SessionMode.Allowed)]
02 public interface ICatchAll
03 {
04 [OperationContract(IsOneWay = false, Action = “*”, ReplyAction = “*”)]
05 Message ProcessMessage(Message message);
06 }
07
08 public class CatchAllService : ICatchAll
09 {
10 public Message ProcessMessage(Message message)
11 {
12
13 …
14 return returnMsg;
15 }
16 }

You need to ensure that two identical copies of the received message are created in the service.
Which code segment should you insert at line 12?

A.
Message msgCopy = message.CreateBufferedCopy(8192) as Message;
Message returnMsg = message.CreateBufferedCopy(8192) as Message;

B.
MessageBuffer buffer = message.CreateBufferedCopy(8192);
Message msgCopy = buffer.CreateMessage();
Message returnMsg = buffer.CreateMessage();

C.
MessageBuffer buffer = message.CreateBufferedCopy(8192);
Message msgCopy = buffer.CreateMessage();
Message returnMsg = msgCopy;

D.
Message msgCopy = message;
Message returnMsg = message;

Explanation:
MessageBuffer Class
Represents a memory buffer that stores an entire message for future consumption.

MessageBuffer.CreateMessage Method
Returns a copy of the original message.

MessageBuffer Class
(http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.messagebuffer.aspx)



Leave a Reply 1

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