Which attribute should you apply to the MessageProcessor class?

You are modifying an existing Windows Communication Foundation (WCF) service that is defined as follows:

[ServiceContract]
public interface IMessageProcessor
{
[OperationContract]
void ProcessMessages();
}
public class MessageProcessor: IMessageProcessor
{
public void ProcessMessage();
SubmitOrder();
}

SubmitOrder makes a call to another service. The ProcessMessage method does not perform as expected under a heavy load.
You need to enable processing of multiple messages. New messages must only be processed when the ProcessMessage method is not processing requests,
or when it is waiting for calls to SubmitOrder to return.

Which attribute should you apply to the MessageProcessor class?

You are modifying an existing Windows Communication Foundation (WCF) service that is defined as follows:

[ServiceContract]
public interface IMessageProcessor
{
[OperationContract]
void ProcessMessages();
}
public class MessageProcessor: IMessageProcessor
{
public void ProcessMessage();
SubmitOrder();
}

SubmitOrder makes a call to another service. The ProcessMessage method does not perform as expected under a heavy load.
You need to enable processing of multiple messages. New messages must only be processed when the ProcessMessage method is not processing requests,
or when it is waiting for calls to SubmitOrder to return.

Which attribute should you apply to the MessageProcessor class?

A.
CallbackBehavior(ConcurrencyMode=ConcurencyMode.Reentrant)

B.
CallbackBehavior(ConcurrencyMode=ConcurrencyMode.Multiple)

C.
ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Reentrant)

D.
ServiceBehavior(ConcurrencyMode=ConcurrencyMode.Multiple)

Explanation:
ConcurrencyMode.Reentrant implies that the service (or callback) processes only one message at a given time (analogous to ConcurencyMode.Single).
To ensure thread safety, Windows Communication Foundation (WCF) locks the InstanceContext processing a message so that no other messages can be processed.
In case of Reentrant mode, the InstanceContext is unlocked just before the service makes an outgoing call thereby allowing the subsequent call,
(which can be reentrant as demonstrated in the sample) to get the lock next time it comes in to the service.

ConcurrencyMode Enumeration
(http://msdn.microsoft.com/en-us/library/system.servicemodel.concurrencymode.aspx)



Leave a Reply 1

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