WCF Communication Host/Client. No reaction on connection-faults

981 views Asked by At

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".

1

There are 1 answers

6
Jan On BEST ANSWER

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.