views:

251

answers:

2

Hi, I'm trying to program a client server based on the callback infrastructure provided by WCF but it isn't working asynchronously.

My client connects to the server calling a login method, where I save the clients callback channel by doing

MyCallback callback = OperationContext.Current.GetCallbackChannel()

After that the server does some processing and uses the callback object to communicate with the client.

All this works, the problem resides on the fact that even though I've set the method in the OperationContract as IsOneWay=true, the server still hangs when doing the call to the client.

I've tested this by launching the server for debug in the visual studio, detaching it, launching the client, calling the above mentioned login method, putting a break point in the implemented callback method of the client, and making the server send a response to the client. The server stops doing what it's supposed to do, waiting for the response of the client.

Any help is appreciated.

A: 

I think the sollution to your problem is to properly set the 'ConcurecyMode' and 'Instance ContextMode' attributes for your service. To do that you must decorate your service declaration with those attributes as shown in the exemple below:

  [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, ConcurrencyMode = ConcurrencyMode.Reentrant)]
    public class SubscriberService: ISubscriberServiceContract
{...}

InstanceContextMode.Single builds your service as a Singleton object so there is only one instance of your service running for all clients;

ConcurencyMode.Reentrant or ConcurencyMode.Multiple enables multithreaded work for the service instance. For 'Multiple' you must take care of thread syncronization in your service.

AlexDrenea
I already had is marked as multiple, and tried with Reentrant and it's the same.I've read that even though a service is marked as oneway it still can block under certain conditions, the problem is that in my case this is the norm instead of an exception. I'm guessing it's related to how the binding is configured but I don't see anything that could change it.Thanks for the help.
Multiple and reentrant didn't work because even though we allow multiple threads at the moment it is configured to allow only one.Yet this doesn't solve the problem because the call locks when it shouldn't.I'll be implementing a thread that handles the sending of the messages.Thanks for everything.
A: 

Did you try to set

[CallbackBehavior(UseSynchronizationContext = false)]

on the client side object implementing the callback interface ?

20c