2013-10-22 82 views
14

我从一个WCF Web服务检索数据,当数据超过0.2亿张唱片,我得到一个例外,这是为下:System.ServiceModel.CommunicationException:基础连接已关闭

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) 

我的网站.config看起来像这样:

<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> 

我确定我的web服务正在从数据库中检索数据。但无法从我发起呼叫的位置转移到我的网站。预先感谢您的帮助。

+0

增加配置文件中的连接超时。 – gleng

+0

在Web.config中提到的绑定中增加maxBufferSize,maxReceivedMessageSize –

回答

15

我最近在.NET 4.0 web应用程序中遇到了与Wcf服务相同的问题。我增加了maxItemsInObjectGraph值,服务器不再抛出异常。文档here表示默认最大值为Int32.MaxValue但我认为这是不正确,最大值为65535

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

你可以做的另一件事是启用跟踪。这是什么我在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> 

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

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

我希望这会有所帮助。

+0

我和OP有类似的问题,增加''为我解决了这个问题。 –

+1

我也有类似的问题。使用服务跟踪日志我发现我的DTO类的序列化错误... – GiveEmTheBoot

+0

链接中的文档是System.Runtime.Serialization类。以下是服务行为的链接,其中显示最大值为65536 http://msdn.microsoft.com/zh-cn/library/ms731809(v=vs.100).aspx – mmeasor

2

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

如果不工作,你可以启用WCF跟踪: wcf tracing

这会给你的下属是什么问题,更多的见解。

0

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

我们有双向导航的父 - >子和父 - >父,我们不得不打断那个连接,而是有父 - >子,并且孩子有一个ID来查找父母,然后错误发生了远。

希望这可以帮助别人!

0

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

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

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