Question

I'm trying to let my service knows when one of the clients is disconnected.

I'm using wsDualHttpBinding.

Currently, I'm tried to use this event :

OperationContext.Current.Channel.Closed += new EventHandler((sender, e) => ClientIsDisconnected(sender, e, currentCallbackChannel));

But this event is never fired...

Please help me to know how it'd be done !

Edit :

Thanks to anderhil, I finally replaced wsDualHttpBinding by netTcpBinding (with the appropriate configuration described here : http://msdn.microsoft.com/en-us/library/ff647180.aspx#Step1).

With netTcpBinding, the Closed event fires without any problem... Still don't know why but it works.

Was it helpful?

Solution

The issue you are having is likely becuase of WsDualHttpBinding. In case you have this binding, two connections are created, from client to service and from service to client.

When the application is deployed over the internet it can create some issues with supporting such applications, you need to be sure that people are not behind the firewall or NAT or etc that can prevent your service to connect back to client.

I still don't know why it doesn't work on local machine when testing, but i will try to resolve it and update the answer.

As you told me more details in our chat, from the nature of your application it's better to use NetTcpBinding. In this case it's easier to understand what is happening cause one connection is created, and you will receive the notifications in case of gracefull close or abort of client.

As i told you before, anyway it's better to create some heartbeat mechanism to have things more reliable in case of unexpected computer or router shutdown.

Also, you can find this good cheat sheet on how to select communication between parties that involve WCF:

wcf binding cheat sheet

OTHER TIPS

The Closed event should occur on a graceful disconnect; is that what's happening? To detect the pure socket disconnect, listen for the Faulted event:

OperationContext.Current.Channel.Faulted += new EventHandler(FaultedHandler);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top