Changing ConcurrencyMode

565 Views Asked by At

I'm using Castle Windsor WCF Facility. The docs say:

If you are switching from WCF activation to Windsor's WcfFacility, please make sure to remove the ServiceBehavior attribute from service type.

How can I then control the concurrency mode?

In vanilla WCF I'd do:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple)]

It seems that with WCF Facility the concurrence mode is set to Single and I can't find a way to change it.

EDIT: The client calls asynchronously BeginFoo method and the call is not blocking on client side. I put logging at the beginning and at the end of the BeginFoo method. The logs indicate that the server call enters and exits BeginFoo method only once at a time.

The following client calls get magically queued.

3

There are 3 best solutions below

0
dzendras On BEST ANSWER

I figured it out.

If you don't specify the attribute, then WCF Facility creates one for you and adds it to

ServiceHost.Description.Behaviors

So the solution is to add an attribute to Behaviors collection (Yes, the attribute implements IServiceBehavior, a bit counterintuitive though...) and set the relevant properties there.

I'm adding the behaviors in WcfServiceModel's extension OnCreated. As at this point the default behavior is already there, I had to remove it first.

5
Friyank On

As I Tried Some ways , You can use

 [OperationContract(IsOneWay=true)]

this will not make client to wait for response and this can work as or replace multiple or reentrant concurrency model

0
ThomasDC On

For anyone interested, here's the code for what dzendras posted earlier:

static void Main(string[] args) {
    _container = new WindsorContainer();
    _container.AddFacility<WcfFacility>();
    _container.Register(Component.For<IHelloService>()
                                 .ImplementedBy<HelloService>()
                                 .AsWcfService(new DefaultServiceModel().OnCreated(OnCreated)));
}

private static void OnCreated(ServiceHost serviceHost)
{
    var serviceBehavior = (ServiceBehaviorAttribute) serviceHost.Description.Behaviors.Single(_ => _ is ServiceBehaviorAttribute);
    serviceBehavior.ConcurrencyMode = ConcurrencyMode.Multiple;
    serviceBehavior.InstanceContextMode = InstanceContextMode.PerSession;
}