大数据接收时WCF Web服务失败

时间:2009-08-25 15:18:35

标签: wcf connection

我正在本地(或远程)调用WCF Web服务,该服务可以正常处理少量数据(约25行< 1K数据ea)。但是当数据变得更大(大约300行)时,Web服务就会失败。 以下是内部异常中的异常,内部异常和堆栈跟踪

该服务在本地执行似乎也花费了不寻常的时间(我添加这个因为它可能会给你一些解决方案的提示)。获取大量数据需要3s服务器端,而小数据需要1s服务器端。但是,运行Web服务(本地)以获取少量数据需要24秒。

我还从我的客户端测试应用程序中包含来自app.config 的绑定信息。

=========绑定信息===========

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="BasicHttpBinding_IFormsService" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="02:00:00" sendTimeout="00:02:00"
          allowCookies="false" bypassProxyOnLocal="false" 
          hostNameComparisonMode="StrongWildcard"
          maxBufferSize="2147483647" maxBufferPoolSize="2147483647" 
          maxReceivedMessageSize="2147483647"
          messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
          useDefaultWebProxy="true">
        <readerQuotas maxDepth="32" maxStringContentLength="1000000000" 
                      maxArrayLength="1000000000"
                      maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        <security mode="None">
           <transport clientCredentialType="None" 
                      proxyCredentialType="None" realm="" />
           <message clientCredentialType="UserName" algorithmSuite="Default" />
        </security>
     </binding>
  </basicHttpBinding>
</bindings>
<client>
  <endpoint 
        address="http://monica-pc/TrialIQSvc/FormsService.svc/FormsService/FormsService.Svc"
        binding="basicHttpBinding" 
        bindingConfiguration="BasicHttpBinding_IFormsService"
        contract="WebService.IFormsService" name="BasicHttpBinding_IFormsService" />
</client>

========= EXCEPTION DATA =============

**Exception**: An error occurred while receiving the HTTP response to http://monica-pc/TrialIQSvc/FormsService.svc/FormsService/FormsService.Svc. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details.

**Inner Exception**: The underlying connection was closed: An unexpected error occurred on a receive.
   **Stack trace**: 
Server stack trace: 
   at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)
   at System.ServiceModel.Channels.HttpChannelFactory.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.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
   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 Test.WebService.IFormsService.GetFormGroupInstance(String formGroupId, String subjectId, String userId)
   at Test.WebService.FormsServiceClient.GetFormGroupInstance(String formGroupId, String subjectId, String userId) in G:\SVNTrialIQ\trunk\Common\trunk\source\Forms\Test\Service References\WebService\Reference.cs:line 59
   at Test.Form1.btnInstanceInfo_Click(Object sender, EventArgs e) in G:\SVNTrialIQ\trunk\Common\trunk\source\Forms\Test\Form1.cs:line 408

5 个答案:

答案 0 :(得分:2)

要获取扩展错误信息,请尝试使用SvcTraceViewer

答案 1 :(得分:2)

有很多事情可能出错。

首先,正如“darin”已经建议的那样 - 尝试打开消息跟踪,看看它产生了什么。

第二 - 你可能会遇到超时。你说你的小数据集大约需要24秒才能返回,你的大数据集大约是12倍(300对25行),所以可能需要288秒 - 但你的sendTimeout设置为2分钟 - 所以这可能是原因。尝试增加该设置让我们说10分钟 - 这应该是充足的时间:

<binding name="BasicHttpBinding_IFormsService" 
          sendTimeout="00:10:00"

如果这不能解决问题 - 您可以尝试使用流媒体来移回大量数据:

<binding name="BasicHttpBinding_IFormsService" 
         transferMode="StreamedResponse">

只要你的回答很大,那就应该有效。当然,您必须重新架构您的客户端调用服务一点来处理流(创建一个操作契约=服务方法返回Stream作为其返回值,并使用流来读取块中的数据从服务器)。如果这是您的常见情况,那可能会起作用并且值得付出努力(并且它将允许您再次减少缓冲区大小,以避免因巨大消息泛滥而导致的拒绝服务攻击)。

有关流媒体的更多信息,请参阅优秀的intro to WCF message streaming

如果没有任何帮助 - 请回来告诉我们!

马克

答案 2 :(得分:0)

可能是您缺少服务器端的某些配置

答案 3 :(得分:0)

试试这个: 在system.web部分中。设置maxRequestLength属性。

<httpRuntime executionTimeout="90" maxRequestLength="1048576" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100"/> 

答案 4 :(得分:0)

此错误可能是由于合同不匹配造成的。考虑下面的三层应用程序......

UI Layer                            
  |    
Process Layer   
  |   
Data Access Layer                  
-> Contract Between Process and UI layer has the same enum with missing (Onhold = 3). Enum: Start = 1, Stop = 2.
-> Contract Between Data Access And Process layer has enum Enum: Start = 1,Stop = 2,Onhold = 3.

在这种情况下,我们将在流程层响应中获得相同的错误。

多层应用程序中的其他合同不匹配也会出现同样的错误。