简体   繁体   English

WCF Web服务无法接收到大数据

[英]WCF Web Service Fails on Receive with Large Data

I am calling a WCF Web Service locally (or remotely) that is working fine with small amounts of data (about 25 lines of < 1K of data ea). 我正在本地(或远程)调用WCF Web服务,该服务可以很好地处理少量数据(大约25行<1K的数据ea)。 But when the data gets larger (about 300 lines) the web service fails. 但是,当数据变大(大约300行)时,Web服务就会失败。 Below is the Exception, Inner Exception, and Stack Trace from the Inner Exception. 以下是异常,内部异常和来自内部异常的堆栈跟踪

The service also seems to be taking unusually long to execute locally (I add this because it may give you some hint in solving). 该服务在本地执行似乎也花费了很长时间(我添加了这个原因是因为它可能会给您一些解决的提示)。 Getting the large amount of data takes 3s server-side and the small about of data takes 1s server-side. 获取大量数据需要3s服务器端,而少量数据大约需要1s服务器端。 However, running the web service (locally) to get the small amount of data back takes 24s. 但是,在本地运行Web服务以获取少量数据需要24秒钟。

I have also included the binding information from the app.config from my client test application. 我还包括了来自客户端测试应用程序的app.config中的绑定信息

=========BINDING INFORMATION=========== =========绑定信息===========

<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

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

There's a number of things that could go wrong. 有很多事情可能出错。

First of all, as "darin" already suggested - try turning on the message tracing and see what that produces. 首先,正如已经建议的那样,尝试打开消息跟踪并查看产生的结果。

Second - you could be running into a timeout. 其次-您可能会遇到超时问题。 You said your small data set took about 24 seconds to return, your larger data set is 12 times as big (300 vs. 25 lines), so that could take 288 seconds - but your sendTimeout is set to 2 minutes - so that might be the reason. 您说您的小型数据集需要大约24秒才能返回,大型数据集是大型数据集的12倍(300对25行),因此可能需要288秒-但sendTimeout设置为2分钟-因此原因。 Try increasing that setting to let's say 10 minutes - that should be ample time: 尝试将该设置增加到10分钟-这应该是足够的时间:

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

If that doesn't solve it - you could try to use streaming in order to move back the large amounts of data: 如果那不能解决问题,您可以尝试使用流传输以移回大量数据:

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

As long as it's only your responses that are big, that should work. 只要您的回应很大,那才行得通。 Of course, you'd have to rearchitect your client calling the service a bit to handle streaming (create an operation contract = service method that returns a Stream as its return value, and use the stream to read the data in chunks from the server). 当然,您必须重新构造您的客户端,以稍微调用服务的方式来处理流(创建一个操作协定=服务方法,该方法返回一个Stream作为其返回值,并使用该流从服务器中分块读取数据) 。 If that's a common scenario for you, that might work and be well worth the effort (and it would allow you to reduce your buffer sizes again, to avoid a denial-of-service attack by being flooded with huge messages). 如果这是您的常见情况,那可能会起作用,并且值得您付出努力(并且它将使您能够再次减小缓冲区大小,从而避免由于被大量消息淹没而导致拒绝服务攻击)。

See a great intro to WCF message streaming for more information on streaming. 有关的更多信息,请参见WCF消息流的精彩介绍

And if nothing helps - come back and let us know! 如果没有帮助-请回来告诉我们!

Marc

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

This error can be because of contract mismatch. 此错误可能是由于合同不匹配造成的。 Consider the three layered application below... 考虑下面的三层应用程序...

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.

In this case we will get the same error in process layer response. 在这种情况下,我们将在处理层响应中得到相同的错误。

The same error comes in other contract mismatch in multilayered application. 同样的错误来自多层应用程序中的其他合同不匹配。

Try this: in the in the system.web section. 尝试以下操作:在system.web部分中。 Set the maxRequestLength attribute. 设置maxRequestLength属性。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM