通信对象 System.ServiceModel.Channels.ServiceChannel 无法用于通信,因为其处于“出错”状态。

通信对象 System.ServiceModel.Channels.ServiceChannel 无法用于通信,因为其处于“出错”状态。
在 System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
在 System.ServiceModel.Channels.ServiceChannelFactory.OnClose(TimeSpan timeout)
在 System.ServiceModel.Channels.ServiceChannelFactory.TypedServiceChannelFactory`1.OnClose(TimeSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
在 System.ServiceModel.ChannelFactory.OnClose(TimeSpan timeout)
在 System.ServiceModel.Channels.CommunicationObject.Close(TimeSpan timeout)
在 System.ServiceModel.ChannelFactory.System.IDisposable.Dispose()

这个错误的原因,在异常信息里有部分信息:可能绑定不匹配导致的错误。

①客户端和服务器安全模式不同,例如客户端启用安全,而服务器没有启用安全;
②客户端和服务器编码模式不同,导致无法匹配错误信息。
③客户端和服务端SOAP版本不同。也可能导致问题。
④客户端和服务端事务设置不同等等。

但是都没有解决问题,后来发现我的返回类型里面有IReadOnlyList<T>,改成IList<T>或者List<T>,问题都可以解决,应该是当前的WCF版本数据契约还不支持IReadOnlyList<T>的原因吧。

原文地址:https://www.cnblogs.com/yanglang/p/6904288.html