2009-01-10 155 views

回答

1

据我所知,故障状态通常是WCF代理的终端。所以不,我不这么认为。

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(); 
} 
+0

(只是为了澄清),这是不完全保持连接断开(正如Marc所说,故障状态意味着(通常)连接关闭,这是在关闭事件中重新创建连接。 – Russell 2010-03-09 00:19:35