WCF错误通信对象System.ServiceModel.Channels.ServiceChanne不能用于通信,因为它处于Faulted状态

11 c# wcf

我们得到了

"通信对象System.ServiceModel.Channels.ServiceChannel不能用于通信,因为它处于Faulted状态."

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

我只能说,当服务不可用时,但垃圾收集器试图销毁对象,通信对象正在调用其服务关闭功能.我们得到例外.

Joh*_*ers 12

当您询问有关异常的问题时,您应该发布整个异常,包括所有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
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,我想知道你的代理实例化是否有一个使用块:

using (var proxy = new WcfProxyClient())
{
    // Use of proxy
}
Run Code Online (Sandbox Code Playgroud)

WCF中存在一个设计缺陷,使其成为.NET中唯一不应使用using块的地方.相反,你需要手工完成.请参阅http://web.archive.org/web/20100703123454/http://old.iserviceoriented.com/blog/post/Indisposable+-+WCF+Gotcha+1.aspx.

另请参阅" WCF客户端using块问题的最佳解决方法是什么? "和" 不可发生的WCF客户端 ".