【问题标题】:maxItemsInObjectGraph ignoredmaxItemsInObjectGraph 被忽略
【发布时间】:2010-02-24 10:46:32
【问题描述】:

我遇到了 WCF 服务的问题,它试图序列化过多的数据。从跟踪中我得到一个错误,说可以序列化或反序列化的元素的最大数量是“65536”,请尝试增加 MaxItemsInObjectGraph 配额。

所以我去修改了这个值,但它只是被忽略了(错误是相同的,具有相同的数字)。所有这些都是服务器端的。我目前正在通过 wget 调用该服务。

我的网络配置是这样的:

<system.serviceModel>  
  <behaviors>
   <serviceBehaviors>
    <behavior name="AlgoMap.Web.MapService.MapServiceBehavior">
       <dataContractSerializer maxItemsInObjectGraph="131072" />
       <serviceMetadata httpGetEnabled="true" />
       <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
   </serviceBehaviors>
  </behaviors>
  <bindings>
   <customBinding>
    <binding name="customBinding0" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:02:00">
      <binaryMessageEncoding>
        <readerQuotas maxDepth="64" maxStringContentLength="16384"
                                maxArrayLength="16384" maxBytesPerRead="16384"
                                maxNameTableCharCount="16384" />
      </binaryMessageEncoding>
      <httpTransport />
    </binding>
   </customBinding>
  </bindings>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  <services>
   <service behaviorConfiguration="AlgoMap.Web.MapService.MapServiceBehavior"
    name="AlgoMap.Web.MapService.MapService">
    <endpoint address="" binding="customBinding" bindingConfiguration="customBinding0"
     contract="AlgoMap.Web.MapService.MapService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
   </service>
  </services>
 </system.serviceModel>



第 2 版,也不起作用:

 <system.serviceModel>  
  <behaviors>

    <endpointBehaviors>
      <behavior name="AlgoMap.Web.MapService.MapServiceEndpointBehavior">
         <dataContractSerializer maxItemsInObjectGraph="131072" />
      </behavior>
    </endpointBehaviors>

   <serviceBehaviors>
    <behavior name="AlgoMap.Web.MapService.MapServiceBehavior">
       <serviceMetadata httpGetEnabled="true" />
       <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
   </serviceBehaviors>
  </behaviors>
  <bindings>
   <customBinding>
    <binding name="customBinding0" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:02:00">
      <binaryMessageEncoding>
        <readerQuotas maxDepth="64" maxStringContentLength="16384"
                                maxArrayLength="16384" maxBytesPerRead="16384"
                                maxNameTableCharCount="16384" />
      </binaryMessageEncoding>
      <httpTransport />
    </binding>
   </customBinding>
  </bindings>

  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
  <services>
   <service behaviorConfiguration="AlgoMap.Web.MapService.MapServiceBehavior"
    name="AlgoMap.Web.MapService.MapService">
     <endpoint 
        address="" binding="customBinding" bindingConfiguration="customBinding0"
        contract="AlgoMap.Web.MapService.MapService" 
        behaviorConfiguration="AlgoMap.Web.MapService.MapServiceEndpointBehavior" />
    <endpoint 
        address="mex" binding="mexHttpBinding" contract="IMetadataExchange"  
        behaviorConfiguration="AlgoMap.Web.MapService.MapServiceEndpointBehavior" />
   </service>
  </services>
 </system.serviceModel>

谁能帮忙?? 谢谢!!

【问题讨论】:

  • 您还需要在客户端配置中进行设置。

标签: wcf


【解决方案1】:

web.config 中的任何设置都被愉快地忽略了,我还没有找到原因。但是我找到了一个解决方法,就是把 MaxItemsInObjectGraph 作为一个类装饰。这完美无缺:

// MyService.svc
// using...

namespace MyNamespace {
  [ServiceContract]
  [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  [ServiceBehavior(MaxItemsInObjectGraph = 65536000)]
  public class MyWebService {

    [OperationContract]
    [WebGet(UriTemplate = "tree/{sessionId}", ResponseFormat = WebMessageFormat.Json)]
    public MyData GetTree(string sessionId) {
    ...
...

【讨论】:

  • 我一直在寻找这个答案 8 小时,非常感谢。
【解决方案2】:

我也遇到了这个问题,在我的例子中,我忘了把这个设置放在我的客户端 app.config 文件中。

【讨论】:

    【解决方案3】:

    可能还小吗?您是否尝试提供更大的值,例如 655360000?请注意,您应该更改客户端和服务器配置文件中的值。我的猜测是你只改变了一部分;)

    【讨论】:

    • 不,不小,只是被服务器忽略了。在异常中,我仍然看到默认限制。我没有任何客户端配置,因为我通过 wget 调用它,在最终产品中我将使用 WebClient 调用它。
    【解决方案4】:

    在 Google 中稍作搜索,您似乎将设置添加到了错误的位置。

    您需要在endPointBehaviors 部分中创建一个新的behavior(不是serviceBehaviors)。

    【讨论】:

      【解决方案5】:

      我也有同样的问题。在类级别使用服务行为属性可以正常工作,这是有道理的。我更喜欢配置级别的更改。我在客户端(web.config)和服务级别(app.config)都添加了配置条目。它能为您提供帮助吗?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-26
        • 2016-06-05
        • 2014-02-25
        • 2011-05-09
        • 2015-02-08
        • 2011-03-27
        相关资源
        最近更新 更多