1

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?

Radek Stromský
  • 838
  • 3
  • 12
  • 27
  • Perhaps a connection with JavaScript and in the beforeunload event? – Silvermind Mar 16 '12 at 10:18
  • I have already tried that. Calling `ScriptableMember` method from JavaScript in the `window.onbeforeunload` event handler. It works exactly the same as I would call it during Application Exit event. – Radek Stromský Mar 16 '12 at 11:04
  • I read somewhere that your second method doesn't work because the server must handle the contract on entry which cannot be done because the client is gone. Have you tried sending the last call with a newly created wcfclient to a method like this: `[ServiceContract] interface IMyContract { [OperationContract(IsOneWay = true)] void Bye() }` – Silvermind Mar 16 '12 at 19:24
  • Is UserLeave() a oneway operation? – Phil Degenhardt Mar 16 '12 at 21:07

1 Answers1

1

I found similar topic here in SO. Aliostad's answer made me think about this once more. You can never be sure you will get the signal from client that he's leaving. So I ended up with timeout solution.

Community
  • 1
  • 1
Radek Stromský
  • 838
  • 3
  • 12
  • 27