2

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.

dzendras
  • 4,721
  • 1
  • 25
  • 20

3 Answers3

2

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.

dzendras
  • 4,721
  • 1
  • 25
  • 20
0

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;
}
ThomasDC
  • 484
  • 3
  • 11
-3

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

Friyank
  • 469
  • 3
  • 8
  • The client doesn't wait. Client is able to issue next requests immediately. It's the service that does not allow concurrent calls. – dzendras Jun 26 '14 at 12:01
  • @dzendras Friyank just said that it **will not** make the client wait – Electric Coffee Jun 26 '14 at 12:11
  • no issue's you can define concurrency mode at method level as , define [ServiceBehavior(ConcurrencyMode= ConcurrencyMode.Multiple)] attribute on top of the method, see if it works – Friyank Jun 26 '14 at 12:12
  • @ElectricCoffee: And I said that the problem is not on the client side, but on the *server* side. – dzendras Jun 26 '14 at 12:33
  • 2
    @Friyank: Have you tried to actually compile your code? ServiceBehaviorAttribute cannot be defined on methods... – dzendras Jun 26 '14 at 12:34