【问题标题】:How do I get the cause of a WCF Client Faulted Event?如何获取 WCF 客户端故障事件的原因?
【发布时间】:2009-11-30 02:44:10
【问题描述】:

如何获取导致 WCF 客户端发生故障事件的异常或错误代码?

private void ConnectionFaultedHandler(object sender, EventArgs e) 
{
    // Darn! Something went wrong.
    // Better clean up.
    this._Connection.Abort();
    this._Connection.InnerChannel.Faulted -= this.ConnectionFaultedHandler;

    // I'd really like to tell the user some detail of what blew up.
    // But there is no Exception (or similar) property on the event.
    this.NotifyUIOfConnectionFailure(e.Exception);  
}

注意,这类似于this thread,除了我 1) 无法以这种方式工作,2) 它似乎正在解决服务端的问题,我想在客户端处理.

编辑:

为了澄清,上述处理程序是长时间(数小时甚至数天)保持打开状态的连接的一部分;它有一个回调接口来接收来自服务的数据。当您调用 Open 之类的方法或属于合约接口的方法时,我不是在询问异常情况,而是由于(例如)有人从您的 PC 上拔下网线或您的 Internet 连接失败而发生的故障。

想象一下它发生在这段代码执行后的某个时间:

private void OpenConnection()
{
    try
    {
         this._Connection.Open();
    } 
    catch (Exception ex)
    {
         // Yes, I should be catching CommunicationsException, 
         // and TimeoutException, but space is short on StackOverflow.
         return;
    }

    Debug.Assert(this._Connection.State == Open);

    this._Connection.InnerChannel.Faulted += this.ConnectionFaultedHandler;
}

【问题讨论】:

    标签: c# wcf exception


    【解决方案1】:

    顺便说一句,你的问题不太清楚

    接收错误与接收异常不同。

    每当您抛出一个异常对象时,该对象将在客户端接收到相应的 catch 块。

    在通道问题(未连接)的情况下收到故障...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-23
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多