Which attribute should you use to decorate the service?

You are developing a Windows Communication Foundation (WCF) service that does not operate on a duplex channel.
You find that operations do not start until all previous operations have finished. The service hosting code contains the following lines.

var service = new WarehouseService();
var host = new ServiceHost(service);

You need to ensure that new operations do not wait for previous operations to finish. Which attribute should you use to decorate the service?

You are developing a Windows Communication Foundation (WCF) service that does not operate on a duplex channel.
You find that operations do not start until all previous operations have finished. The service hosting code contains the following lines.

var service = new WarehouseService();
var host = new ServiceHost(service);

You need to ensure that new operations do not wait for previous operations to finish. Which attribute should you use to decorate the service?

A.
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single, ConcurrencyMode=ConcurrencyMode.Multiple)]

B.
[CallbackBehavior(ConcurrencyMode=ConcurrencyMode.Multiple)]

C.
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single, ConcurrencyMode=ConcurrencyMode.Single)]

D.
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single, ConcurrencyMode=ConcurrencyMode.Reentrant)]

Explanation:
PerSession A new InstanceContext object is created for each session.
PerCall A new InstanceContext object is created prior to and recycled subsequent to each call.
If the channel does not create a session this value behaves as if it were PerCall.
Single Only one InstanceContext object is used for all incoming calls and is not recycled subsequent to the calls.
If a service object does not exist, one is created.

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

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

“If the InstanceContextMode value is set to Single the result is that your service can only process one message at a time
unless you also set the ConcurrencyMode value to Multiple.”

So single is fine to use for InstanceContextMode



Leave a Reply 2

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


Y

Y

CallBack Behavior? Seriously? It must be A