2012-06-22 57 views
3

我有一個WCF服務,可以根據輸入參數返回大量數據。WCF錯誤「套接字連接已處理」

該服務作爲ServiceHost可執行文件在我的機器上運行,我現在使用WCF Test客戶端進行測試。

這裏是我的主機配置:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <netTcpBinding> 
       <binding name="NetTcpBinding_ExchangeRepository" 
         closeTimeout="00:01:00" openTimeout="00:01:00" 
         receiveTimeout="00:10:00" sendTimeout="00:10:00" 
         transactionFlow="false" transferMode="Streamed" 
         transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" 
         listenBacklog="500" maxBufferPoolSize="2147483646" 
         maxBufferSize="2147483646" maxConnections="500" 
         maxReceivedMessageSize="2147483647" > 
        <readerQuotas 
         maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" 
         maxBytesPerRead="4096" maxNameTableCharCount="2147483647" /> 
        <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" /> 
        <security mode="None"> 
        </security> 
       </binding>   
      </netTcpBinding> 
     </bindings>   
     <services>   
      <service name="MyCompany.MyApplication.DataServices.ExchangeRepository" 
        behaviorConfiguration="MyCompany.MyApplication.DataServicesBehavior"> 
       <endpoint address ="" 
          binding="netTcpBinding" 
          contract="MyCompany.MyApplication.DataServices.IExchangeRepository" 
          bindingConfiguration="NetTcpBinding_ExchangeRepository" 
          behaviorConfiguration="MyCompany.MyApplication.EndpointBehavior"> 
        <identity> 
         <dns value="localhost"/> 
        </identity> 
       </endpoint> 
       <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
       <host> 
        <baseAddresses> 
         <add baseAddress = "net.tcp://localhost:8896/ExchangeRepository/" /> 
         <add baseAddress = "http://localhost:8895/ExchangeRepository/" /> 
        </baseAddresses> 
       </host> 
      </service> 
     </services>   
     <behaviors> 
      <serviceBehaviors> 
       <behavior name="MyCompany.MyApplication.DataServicesBehavior"> 
        <dataContractSerializer maxItemsInObjectGraph="2147483646"/> 
        <serviceMetadata httpGetEnabled="True"/> 
        <serviceDebug includeExceptionDetailInFaults="True" /> 
       </behavior> 
      </serviceBehaviors> 
      <endpointBehaviors> 
       <behavior name="MyCompany.MyApplication.EndpointBehavior"> 
        <dataContractSerializer maxItemsInObjectGraph="2147483646"/> 
       </behavior> 
      </endpointBehaviors> 
     </behaviors>  
    </system.serviceModel> 
</configuration> 

這裏是我的客戶端配置:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <system.serviceModel> 
     <behaviors> 
      <endpointBehaviors> 
       <behavior name="endpointBehaviour"> 
        <dataContractSerializer maxItemsInObjectGraph="2147483647" /> 
       </behavior> 
      </endpointBehaviors> 
     </behaviors> 
     <bindings> 
      <netTcpBinding> 
       <binding name="NetTcpBinding_IExchangeRepository" closeTimeout="00:10:00" 
        openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" 
        transactionFlow="false" transferMode="Streamed" transactionProtocol="OleTransactions" 
        hostNameComparisonMode="StrongWildcard" listenBacklog="10" 
        maxBufferPoolSize="524288" maxBufferSize="2147483647" maxConnections="10" 
        maxReceivedMessageSize="2147483647"> 
        <readerQuotas maxDepth="32" maxStringContentLength="2147483647" 
         maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="2147483647" /> 
        <reliableSession ordered="true" inactivityTimeout="00:10:00" 
         enabled="false" /> 
        <security mode="None"> 
         <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> 
         <message clientCredentialType="Windows" /> 
        </security> 
       </binding> 
      </netTcpBinding> 
     </bindings> 
     <client> 
      <endpoint address="net.tcp://localhost:8896/ExchangeRepository/" 
       behaviorConfiguration="endpointBehaviour" binding="netTcpBinding" 
       bindingConfiguration="NetTcpBinding_IExchangeRepository" contract="IExchangeRepository" 
       name="NetTcpBinding_IExchangeRepository"> 
       <identity> 
        <dns value="localhost" /> 
       </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
</configuration> 

,這裏是我得到的錯誤:

The socket connection has been disposed. 

Server stack trace: 
    at System.ServiceModel.Channels.SocketConnection.ThrowIfNotOpen() 
    at System.ServiceModel.Channels.SocketConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout) 
    at System.ServiceModel.Channels.DelegatingConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout) 
    at System.ServiceModel.Channels.PreReadConnection.Read(Byte[] buffer, Int32 offset, Int32 size, TimeSpan timeout) 
    at System.ServiceModel.Channels.SingletonConnectionReader.SingletonInputConnectionStream.ReadCore(Byte[] buffer, Int32 offset, Int32 count) 
    at System.ServiceModel.Channels.SingletonConnectionReader.SingletonInputConnectionStream.Read(Byte[] buffer, Int32 offset, Int32 count) 
    at System.ServiceModel.Channels.MaxMessageSizeStream.Read(Byte[] buffer, Int32 offset, Int32 count) 
    at System.ServiceModel.Channels.SingletonConnectionReader.Close(TimeSpan timeout) 
    at System.ServiceModel.Channels.SingletonConnectionReader.SingletonInputConnectionStream.Close() 
    at System.ServiceModel.Channels.DelegatingStream.Close() 
    at System.Xml.XmlBufferReader.Close() 
    at System.Xml.XmlBaseReader.Close() 
    at System.Xml.XmlBinaryReader.Close() 
    at System.Xml.XmlReader.Dispose(Boolean disposing) 
    at System.Xml.XmlReader.Dispose() 
    at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeBodyContents(Message message, Object[] parameters, Boolean isRequest) 
    at System.ServiceModel.Dispatcher.OperationFormatter.DeserializeReply(Message message, Object[] parameters) 
    at System.ServiceModel.Dispatcher.ProxyOperationRuntime.AfterReply(ProxyRpc& rpc) 
    at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) 
    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) 

Exception rethrown at [0]: 
    at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) 
    at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) 
    at IExchangeRepository.SearchExchangeRequest(String AccountNumber, Int32 StatusCode, Int32 StartDate, Int32 EndDate) 
    at ExchangeRepositoryClient.SearchExchangeRequest(String AccountNumber, Int32 StatusCode, Int32 StartDate, Int32 EndDate) 

Inner Exception: 
The socket connection has been disposed. 
Object name: 'System.ServiceModel.Channels.SocketConnection'. 

的錯誤是發生當返回的數據超過一些記錄數時。用更少的數據一切都按預期工作。

關於如何解決這個問題的任何建議?

+2

第一步是啓用跟蹤 - http://blogs.msdn.com/b/madhuponduru/archive/2006/05/18/601458.aspx – EkoostikMartin

+2

這很難說,但我的猜測是,你有一個'using(){}'塊在某個地方完成並處理一些東西,而堆棧仍然在傳輸數據。儘管很難獲得幫助,但沒有看到更多(可能還有很多)代碼。 – CodingGorilla

+0

這一切都是由愚蠢的數據問題造成的。錯誤信息絕對沒用。啓用跟蹤允許查看實際的異常。謝謝EkoostikMartin! –

回答

1

這一切都是由愚蠢的數據問題造成的。 錯誤消息絕對沒用。啓用跟蹤允許查看實際的異常。 謝謝EkoostikMartin!