我将此示例用于我的 wcf 服务: http ://www.codeproject.com/KB/IP/WCFWPFChatRoot.aspx?msg=3713905#xx3713905xx
但是如果服务器停止,客户端就不会得到它......
该示例通过以下方式处理它:
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();
}
但是,如果我停止主机或它崩溃了(ALT+F4),客户端不会得到它。连接状态仍然是“已连接”。