2

i used this example for my wcf-service: http://www.codeproject.com/KB/IP/WCFWPFChatRoot.aspx?msg=3713905#xx3713905xx

But if the server stops, the clients dont get it...

The example handled it with:

proxy.Open();

proxy.InnerDuplexChannel.Faulted += 
  new EventHandler(InnerDuplexChannel_Faulted);
proxy.InnerDuplexChannel.Opened += 
  new EventHandler(InnerDuplexChannel_Opened);
proxy.InnerDuplexChannel.Closed += 
  new EventHandler(InnerDuplexChannel_Closed);

void InnerDuplexChannel_Closed(object sender, EventArgs e)
{
    if (!this.Dispatcher.CheckAccess())
    {
        this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, 
                        new FaultedInvoker(HandleProxy));
        return;
    }
    HandleProxy();
}


void InnerDuplexChannel_Faulted(object sender, EventArgs e)
{
    if (!this.Dispatcher.CheckAccess())
    {
        this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, 
                        new FaultedInvoker(HandleProxy));
        return;
    }
    HandleProxy();
}

But if i stop the host or it crashed (ALT+F4), the clients dont get it. The connectionstate is still "connected".

John Saunders
  • 160,644
  • 26
  • 247
  • 397
user437899
  • 8,879
  • 13
  • 51
  • 71

1 Answers1

2

The problem lies in the underlying TCP protocol. When the connection dies unexpected, TCP won't inform the other party immediately. There are timeouts normally in the range of hours which you can eventually configure in the used TCP stack - in your case somewhere in the windows registry. But i would not recommend that, because it affects your whole machine.

But you will get an error when you try to send data on that nonexisting connection the next time.

So if you want to know wheather your connection is still alive or not, you have to send a small message at regular intervals.

Jan
  • 15,802
  • 5
  • 35
  • 59
  • Hi jan, i thought that too. But if i send a Message with proxy.Say(new Message()); nothing unexpected happens. I can check the connectionstate after sending the message, but the connectionstate is still connected. – user437899 Dec 29 '10 at 18:13
  • Is your service using the udp protocol? There is nothing like a *connection* which can be closed or opened. – Jan Dec 29 '10 at 18:17
  • No, the example is use (http://www.codeproject.com/KB/IP/WCFWPFChatRoot.aspx) uses TCP. I start the host with ServiceHost host = ServiceHost(...); host.Open(); and the clients connect with ChatClient proxy = ChatClient(...); proxy.Open(); – user437899 Dec 29 '10 at 18:27
  • Are you really sure, you can call a method on a wcf channel uzsing tcp where the host is not longer running? I can't believe that. – Jan Dec 29 '10 at 18:35
  • Yes, if you download the example-chatprojekt (you must start the server with admin-privileges) you can test it. And after you stop the server/host or close it, the clients can still use the say(Message msg)-methode without getting an error – user437899 Dec 29 '10 at 19:12
  • Ahh Yes, IsOneWay = true. Oneway means the server sends no response. I will test it with an two-way operation. thank you :> – user437899 Dec 29 '10 at 20:23