2012-06-07 208 views
1

我在使用WCF客户端进行测试时遇到了我的wcf服务问题。当我调试时,我发现数据从函数中返回,但在响应期间出错。有人能帮我弄清楚我错过了什么吗?接收HTTP响应错误时发生错误

这是我的服务配置文件:

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) 
+1

你得到的错误是什么? – fenix2222

+0

无法从传输连接读取数据:现有连接被远程主机强制关闭。 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请求,布尔userRetrievedStream,布尔probeRead) 内部例外: 现有连接被远程主机 强制关闭在System.Net.Sockets.Socket.Receive(Byte []缓冲区,Int32偏移量,Int32大小,SocketFlags socketFlags) –

+0

我还发现端点有一个名称值,我把它拿出来。尽管 –

回答

4

首先启用您的服务Tracing和看看有什么异常的原因。

此外,您可能会考虑在您的服务器和客户端上增加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。

相关问题