I have fully working duplex messaging solution for Silverlight application. Now I would like to add one feature to it. When user leaves the application I want to notify the server about that by sending the last message before exit.
I have tried to send duplex message during Application Exit event, but DuplexServiceClient
is already in CommunicationState.Faulted
state.
I've also tried to establish new connection and send the message. Everything seemed to be okay on the client side, but no message has been send at all. I checked that twice by using Fiddler.
App.Current.Exit += (s, e) =>
{
var dsc = new DuplexServiceClient(_binding, new EndpointAddress("../Services/MyService.svc"));
dsc.SendToServiceAsync(new UserLeave());
};
Crucial thing is, that I need to notify the server immediately after user leaves the application, so timeouts or similar workarounds are not good enough for me in this situation.
Does anybody have a working solution?