System.ServiceModel.CommunicationException:基础连接已关闭

我正在从wcf Web服务中检索数据,当数据超过20万条记录时,我得到一个exception,如下所示:

System.ServiceModel.CommunicationException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> System.Net.WebException: The underlying connection was closed: A connection that was expected to be kept alive was closed by the server. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetResponse() at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) --- End of inner exception stack trace --- Server stack trace: at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason) at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout) at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout) at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) 

我的web.config看起来像这样:

             

我确信我的Web服务正在从数据库中检索数据。 但无法从我发起呼叫的地方转移到我的网站。 在此先感谢您的帮助。

我最近在.Net 4.0网络应用程序中遇到了与Wcf服务相同的问题。 我增加了maxItemsInObjectGraph值,服务器不再抛出exception。 这里的文档说默认最大值是Int32.MaxValue,但我认为它是不正确的,最大值是65535。

         

您可以做的另一件事是启用跟踪。 这是我在web.config中的示例:

          

如果双击Traces.svclog,Windows应该打开Microsoft服务跟踪查看器。

如果使用Microsoft WCF测试客户端测试服务,请确保更改默认客户端配置以匹配服务器设置(这包括客户端端点行为),以确保客户端可以从服务器接收响应。

我希望这有帮助。

使您的客户端basicHttpBinding与您的服务器绑定相同。 这是一个非常常见的错误,只能更改一个绑定而不是服务器和客户端绑定。

如果这不起作用,您可以启用wcf跟踪: wcf跟踪

这将为您提供有关底层问题的更多见解。

我们在对象图中有一个循环返回。 我知道这可能不是你的问题但我在这里添加它以防其他人有同样的问题。 我们启用了includeExceptionDetailInFaults,但没有在任何客户端(我们的应用程序或WCF测试客户端)中收到错误。 幸运的是它出现在服务器日志中,所以我们能够找到它。

我们有父 – >孩子和孩子 – >双向导航的父母,我们不得不打破这个链接,而是让父 – >孩子,并且孩子有一个id来查找父母,然后错误就消失了。

希望这有助于某人!

将以下配置添加到wcf服务配置中。 并查看c:\ log \ Traces.svclog文件。 我的例外是扔掉;

尝试序列化参数时出错.InstallException消息为’枚举值’0’对于类型’ThyCams2014.XrmBase.new_filingstatu’无效且无法序列化。 确保存在必要的枚举值,并且如果类型具有DataContractAttribute attrienter code herebute,则使用EnumMemberAttribute属性标记。 有关更多详细信息,请参阅InnerException。

            

这句话解决了我的问题:

 db.ContextConfiguration.ProxyCreationEnabled = false;