删除WCF服务答案的大小限制

时间:2009-12-09 15:09:25

标签: c# wcf

我创建了一个WCF服务,它在W2008-Server上运行操作并返回数据结构。问题是,这个结果可能比标准服务配置似乎更接受。所以我试图增加(或删除)这个最大尺寸,但似乎,我没有找到正确的属性。

在WCF的App.config中,我更改了basicHttpBinding的以下值:

  • MaxBufferPoolSize - > 6553600
  • MaxBufferSize - > 6553600
  • MaxReceiveMessageSize - > 6553600

ReaderQuotas:

  • MaxArrayLenght - > 0
  • MaxBytesPerRead - > 0
  • MaxDepth - > 0
  • MaxNameTableCharCount - > 0
  • MaxStringContentLength - > 0

然后我启动WCF-Testclient来调用该服务。我确保basicHttpBinding的属性值等于配置中的值。当我以某种方式调用服务时,结果集相当小,一切正常。但是当这个尺寸增加时,我最终会得到错误(翻译自德语):

  

收到http://localhost:8731/Design_Time_Addresses/DiscoDataSource/Service1/的http答案时出错。可能的原因:Endpointbinding不使用HTTP协议,或者服务器取消了HTTP-requestcontext。

     

服务器堆栈跟踪:

     

at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException,HttpWebRequest request,HttpAbortReason abortReason)

     

at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)

     

在System.ServiceModel.Channels.RequestChannel.Request(消息消息,TimeSpan超时)

     

在System.ServiceModel.Dispatcher.RequestChannelBinder.Request(消息消息,TimeSpan超时)

     

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)

     

在System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall,ProxyOperationRuntime operation)

     

在System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

我想配置服务以返回结果而不管大小。有谁知道,我需要在哪里更改配置?

提前致谢, 弗兰克

2 个答案:

答案 0 :(得分:6)

如果您有大量正在序列化的对象,WCF将达到配置的限制和barf。您已经尝试过所有标准项目,但是您遗漏了一项:maxItemsInObjectGraph。与其他配置值一样,您需要将其设置为服务器端客户端。这是一个带有不必要的大值的示例配置snippit:

<system.serviceModel>
 <behaviors>
   <serviceBehaviors>
     <behavior name="ServiceBehavior">
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
     </behavior>
   </serviceBehaviors>
   <endpointBehaviors>
     <behavior name="ClientBehavior">
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
     </behavior>
   </endpointBehaviors>
 </behaviors>
</system.serviceModel>

我显然省略了很多标签,有利于说明.config文件中出现maxItemsInObjectGraph的位置。

答案 1 :(得分:2)

您是否也在客户端和服务器端更改了这些值?你需要在通信的两端改变它们 - 只有它才能起作用。

如果您未在服务器端更改它们,则较小的值(客户端和服务器值)将“赢”。

然而,可能只是你的超时设置导致服务器中止。在你的绑定上,你可以调整超时 - 默认情况下,它是60秒 - 所以如果抓取数据并根据需要组装它需要更多时间,你需要调整绑定上的SendTimeout,而不是大小设置.....