My WCF service uses netTcpBinding, and has a callback object.
I need to service multiple concurrent clients, and mantain sessions, so the service is decorated with
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple]
To avoid thread deadlocks, the callback class is decorated with
[CallbackBehavior(UseSynchronizationContext=false)]
and I use SynchronizationContext
to execute the method in the UI thread.
The problem is that sometimes the channel gest closed with no reason (ICommunicationObject.Closing
event gets fired). After that, I get exceptions in any subsequent service call.
Looking in the trace file, the last message is a callback call, however, the callback method never gets invoked. There are no exceptions.
After some debugging I identified that this happens only when the callback call is made in the middle of a synchronous operation. The steps would be this:
- Call to service method
A
withIsOneWay=true
- Call to service method
B
withIsOneWay=false
A
invokes a callback method, butB
is still executing.
This shouldn t be a problem because the callback has UseSynchronizationContext=false
, so the callback call could be attended in a separate thread.
I was unable to reproduce the problem in a simpler scenario. Following these steps in a simple project executes successfully.
Any idea of what could be happening or how to identify the problem?