System.ServiceModel.CommunicationException:基础连接已关闭 [英] System.ServiceModel.CommunicationException: The underlying connection was closed

查看:1523
本文介绍了System.ServiceModel.CommunicationException:基础连接已关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是从一个WCF Web服务中检索数据,并且在数据超过20万条记录,我得到一个例外,这是为下:

  System.ServiceModel.CommunicationException:基础连接已经关闭:预计保持在人世的连接被服务器关闭。 ---> System.Net.WebException:基础连接已关闭:预计保持在人世的连接被服务器关闭。 ---> System.IO.IOException:无法读取传输连接的数据:一个现有的连接被强行关闭远程主机。 ---> System.Net.Sockets.SocketException:一个现有的连接被强行关闭远程主机
在System.Net.Sockets.Socket.Receive(字节[]缓冲区的Int32偏移的Int32大小的SocketFlags的SocketFlags)
在System.Net.Sockets.NetworkStream.Read(字节[]缓冲区的Int32偏移的Int32大小)
---内部异常堆栈跟踪的结尾---
在System.Net.Sockets.NetworkStream.Read(字节[]缓冲区的Int32偏移的Int32大小)
在System.Net.PooledStream.Read(字节[]缓冲区的Int32偏移的Int32大小)
在System.Net.Connection.SyncRead(HttpWebRequest的要求,布尔userRetrievedStream,布尔probeRead)
---内部异常堆栈跟踪的结尾---
在System.Net.HttpWebRequest.GetResponse()
在System.ServiceModel.Channels.HttpChannelFactory`1.Htt$p$pquestChannel.HttpChannelRequest.WaitForReply(TimeSpan时间到)
---内部异常堆栈跟踪的结尾---

服务器堆栈跟踪:
在System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException,HttpWebRequest的要求,HttpAbortReason abortReason)
在System.ServiceModel.Channels.HttpChannelFactory`1.Htt$p$pquestChannel.HttpChannelRequest.WaitForReply(TimeSpan时间到)
在System.ServiceModel.Channels.RequestChannel.Request(消息的消息,时间跨度超时)
在System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息的消息,时间跨度超时)
在System.ServiceModel.Channels.ServiceChannel.Call(串动,布尔单向,ProxyOperationRuntime操作,对象[]插件,对象[]出局,时间跨度超时)
在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime操作)
在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(即时聊天消息)
 

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

 < basicHttpBinding的>
  <绑定名称=BasicHttpBinding_IServicecloseTimeout =00:01:00openTimeout =00:01:00receiveTimeout =00:10:00的SendTimeout =00:01:00
             maxBufferSize =2147483647maxBufferPoolSize =2147483647maxReceivedMessageSize =2147483647
             allowCookies =假bypassProxyOnLocal =假hostNameComparisonMode =StrongWildcard
             messageEncoding =文本textEncoding =UTF-8transferMode =StreamedResponseuseDefaultWebProxy =真>
    < readerQuotas MAXDEPTH =32maxStringContentLength =2147483647maxArrayLength =2147483647
                  maxBytesPerRead =2147483647maxNameTableCharCount =2147483647/>
    <安全模式=无>
      <交通运输clientCredentialType =无proxyCredentialType =无的境界=/>
      <消息clientCredentialType =用户名algorithmSuite =默认/>
    < /安全>
  < /装订>
  <结合maxReceivedMessageSize =2147483647allowCookies =真正的>
    < readerQuotas MAXDEPTH =32maxStringContentLength =2147483647maxArrayLength =2147483647maxBytesPerRead =2147483647
maxNameTableCharCount =2147483647/>
  < /装订>
< / basicHttpBinding的>
 

我相信,我的网络服务是从数据库中检索数据。但无法从我发起的呼叫转移到我的网页。感谢您事先的任何帮助。

解决方案

我最近同样的问题,在.NET 4.0的Web应用程序的WCF服务

。我增加了maxItemsInObjectGraph价值和服务器没有再抛出异常。该文件<一个href="http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.maxitemsinobjectgraph%28v=vs.100%29.aspx">here说默认的最大值为Int32.MaxValue但我认为这是不正确,最大值为65535。

 &LT; serviceBehaviors&GT;
    &LT;行为NAME =ServiceBehaviour&GT;
      &LT; D​​ataContractSerializer的maxItemsInObjectGraph =6553500/&GT;
      &LT; serviceMetadata httpGetEnabled =真/&GT;
      &LT; serviceDebug includeExceptionDetailInFaults =真/&GT;
    &LT; /行为&GT;
  &LT; / serviceBehaviors&GT;
 

其他的事情你可以做的是使跟踪。这是我在web.config中的一个例子:

 &LT; System.Diagnostics程序&GT;
  &LT;源&GT;
    &lt;信源名=System.ServiceModel
            switchValue =信息,ActivityTracing
            propagateActivity =真正的&GT;
      &LT;听众&GT;
        &LT;添加名称=TraceListener的
            TYPE =System.Diagnostics.XmlWriterTraceListener
            initializeData =C:\ TEMP \登录\ Traces.svclog/&GT;
      &LT; /听众&GT;
    &LT; /源&GT;
  &LT; /来源&GT;
&LT; /system.diagnostics>
 

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

如果您测试与微软WCF测试客户端服务,确保您更改默认客户端配置相匹配的服务器设置(包括客户端的端点行为),以确保客户端可以接收来自服务器的响应。

我希望这有助于。

I am retrieving data from a wcf web service and when data is more than 0.2 million records i get an exception which is as under:

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)

My web.config looks like this :

<basicHttpBinding>
  <binding name="BasicHttpBinding_IService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
             maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
             allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
             messageEncoding="Text" textEncoding="utf-8" transferMode="StreamedResponse" useDefaultWebProxy="true">
    <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                  maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    <security mode="None">
      <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
      <message clientCredentialType="UserName" algorithmSuite="Default" />
    </security>
  </binding>
  <binding maxReceivedMessageSize="2147483647" allowCookies="true">
    <readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647" />
  </binding>
</basicHttpBinding>

I am sure that my web service is retrieving data from DB. but is unable to transfer to my web from where i initiated the call. Thanks in advance for any help.

解决方案

I had recently the same problem with a Wcf service within a .Net 4.0 web app. I increased the maxItemsInObjectGraph value and server didn't throw the exception anymore. The documentation here says the default maximum is Int32.MaxValue but I think it is incorrect, the maximum value is 65535.

   <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <dataContractSerializer maxItemsInObjectGraph="6553500"/>
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>

The other thing you can do is enable tracing. This is an example of what I have in the web.config:

<system.diagnostics>
  <sources>
    <source name="System.ServiceModel"
            switchValue="Information, ActivityTracing"
            propagateActivity="true">
      <listeners>
        <add name="traceListener"
            type="System.Diagnostics.XmlWriterTraceListener"
            initializeData= "c:\temp\log\Traces.svclog" />
      </listeners>
    </source>
  </sources>
</system.diagnostics>

If you double click on the Traces.svclog, windows should open the Microsoft Service Trace Viewer.

If you test your service with the Microsoft WCF Test Client make sure you change the default client config to match the server settings (this includes the client endpoint behavior) to make sure the client can receive the response from the server.

I hope this helps.

这篇关于System.ServiceModel.CommunicationException:基础连接已关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆