即使出现故障状态,如何让我的WCF服务客户端与WinForm保持连接?
感谢。
答案 0 :(得分:3)
回答我自己:)
您可以订阅InnerChannel活动
svc.InnerChannel.Closed += InnerChannel_Error;
svc.InnerChannel.Closing += InnerChannel_Error;
svc.InnerChannel.Faulted += InnerChannel_Error;
然后处理异常并重新创建服务代理
private void InnerChannel_Error(object sender, EventArgs e)
{
var svc = _entrepotService as EntrepotServiceProxy;
try
{
if (svc != null)
{
if (svc.State != CommunicationState.Faulted)
{
svc.Close();
}
else
{
svc.Abort();
}
}
}
catch (CommunicationException)
{
if (svc != null) svc.Abort();
}
catch (TimeoutException)
{
if (svc != null) svc.Abort();
}
catch
{
if (svc != null) svc.Abort();
throw;
}
_entrepotService = new EntrepotServiceProxy();
}
答案 1 :(得分:1)
据我所知,故障状态通常是WCF代理的终端。所以不,我不这么认为。