maxItemsInObjectGraph被忽略

时间:2010-02-24 10:46:33

标签: wcf

我遇到了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>

任何人都可以帮忙吗? 谢谢!

5 个答案:

答案 0 :(得分:10)

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) {
    ...
...

答案 1 :(得分:3)

我也碰到了这个,在我的实例中,我忘记将此设置放在我的客户端app.config文件中。

答案 2 :(得分:1)

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

答案 3 :(得分:1)

通过Google中的小搜索,您似乎将设置添加到了错误的位置。

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

答案 4 :(得分:1)

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