簡體   English   中英

收到HTTP響應錯誤時發生錯誤

[英]An error occurred while receiving the HTTP response error

在使用WCF客戶端進行測試時,我遇到了與wcf服務有關的問題。 當我調試時,我看到數據從函數返回,但它在響應期間出錯。 有人能幫助我弄清楚我錯過了什么嗎?

這是我的服務和配置文件:

public List<PO> GetAllPOs()
{
    var data = new List<PO>();
    try
    {
        var manager = new EntityReaderManager<PO>(ConfigurationManager.AppSettings("FilemakerDB"]);
        data = manager.GetEntityList();
    }
    catch (Exception ex)
    {
        ILogger logger = new Logger(typeof(FilemakerDataService)); 
        logger.Error(ex.Message);

    }

   return data;
}

這是配置文件:

<system.serviceModel>    
    <diagnostics>
      <messageLogging logEntireMessage="true" logKnownPii="true" logMalformedMessages="true"
        logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"
        maxSizeOfMessageToLog="2147483647" />
      <endToEndTracing propagateActivity="true" activityTracing="false"
        messageFlowTracing="true" />
    </diagnostics>

    <bindings>
    <wsHttpBinding>
      <binding name="Custom.WSHTTPBinding.Configuration" closeTimeout="10:10:00"
        openTimeout="10:10:00" receiveTimeout="10:10:00" sendTimeout="10:10:00"
        maxBufferPoolSize="655360" maxReceivedMessageSize="655360">

        <security mode="None" />
      </binding>
    </wsHttpBinding>
  </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
    <services>
      <service behaviorConfiguration="Custom.ServiceBehavior" name="AerWorldwide.Service.Web.FilemakerData.FilemakerDataService">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Custom.WSHTTPBinding.Configuration"
          name="Custom.WSHTTPBinding.Configuration" contract="AerWorldwide.Service.Web.FilemakerData.IFilemakerDataService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  <behaviors>
    <serviceBehaviors>
      <behavior name="Custom.ServiceBehavior">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
  </behaviors>    
</system.serviceModel>

錯誤:

Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
    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)
Inner Exception: An existing connection was forcibly closed by the remote host
    at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) 

首先啟用對您的服務的跟蹤 ,並查看異常的原因。

您還可以考慮在服務器和客戶端增加ReaderQuotas,以便傳輸更大的數據而不會出現任何問題。 樣本如下所示:

<wsHttpBinding>
      <binding name="Custom.WSHTTPBinding.Configuration" closeTimeout="10:10:00"
        openTimeout="10:10:00" receiveTimeout="10:10:00" sendTimeout="10:10:00"
        maxBufferPoolSize="655360" maxReceivedMessageSize="655360">
         <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
              maxArrayLength="2147483647" maxBytesPerRead="2147483647"
              maxNameTableCharCount="2147483647" />
        <security mode="None" />
      </binding>
    </wsHttpBinding>

此外,我在您的代碼中看到您正在直接傳遞實體框架提取的對象。 在某些情況下,實體框架對象不會被反序列化並可能導致異常。 創建一個簡單的POCO,然后填充獲取的數據並返回POCO。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM