【问题标题】:WCF Error The communication object, System.ServiceModel.Channels.ServiceChanne, cannot be used for communication because it is in the Faulted stateWCF 错误通信对象 System.ServiceModel.Channels.ServiceChanne 无法用于通信,因为它处于故障状态
【发布时间】:2010-10-19 02:59:10
【问题描述】:

我们得到

“通信对象 System.ServiceModel.Channels.ServiceChannel 无法用于通信,因为它处于故障状态。”

我们关闭应用程序时的消息。谁能告诉我如何解决它?我们知道这是试图关闭的通信通道,但由于服务不可用或处于故障状态而无法关闭。

我只能说,当服务不可用,但垃圾收集器试图销毁对象时,通信对象正在调用它的服务关闭函数。我们得到了异常。

【问题讨论】:

  • 不会回答,因为我不能告诉你为什么它有问题;但是你可以在尝试关闭它之前检查它是否处于故障状态。

标签: c# wcf


【解决方案1】:

当您询问有关异常的问题时,您应该发布整个异常,包括所有 InnerException 实例。您应该捕获异常,显示 ex.ToString(),然后用“throw”重新抛出异常:

try {
    // Do whatever causes the exception
} catch (Exception ex) {
    Console.WriteLine(ex.ToString());  // Or Debug.Print, or whatever
    throw; // So exception propagation will continue
}

在这种情况下,我想知道您的代理实例周围是否有 using 块:

using (var proxy = new WcfProxyClient())
{
    // Use of proxy
}

WCF 中有一个设计缺陷,这使得它成为 .NET 中唯一不应该使用 using 块的地方。相反,您需要手动完成。见http://web.archive.org/web/20100703123454/http://old.iserviceoriented.com/blog/post/Indisposable+-+WCF+Gotcha+1.aspx

另请参阅“What is the best workaround for the WCF client using block issue?”和“Indisposable WCF clients”。

【讨论】:

  • 仅供参考 - 链接已损坏。
  • @AlexR:谢谢。通过 Wayback Machine 修复,并添加了另外两个链接。
【解决方案2】:

看看代理项目here

我们遇到了类似的问题,这种技术解决了它。它基本上涉及从一个类继承,该类会在出现故障时自动重新创建通道。

【讨论】:

    猜你喜欢
    • 2012-03-13
    • 1970-01-01
    • 2012-11-02
    • 2019-10-27
    • 2013-08-16
    相关资源
    最近更新 更多