代码之家  ›  专栏  ›  技术社区  ›  Palantir

已忽略Maxitemsinobjectgraph

wcf
  •  7
  • Palantir  · 技术社区  · 15 年前

    我有一个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 回复  |  直到 13 年前
        1
  •  10
  •   Palantir    15 年前

    任何放在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) {
        ...
    ...
    
        2
  •  3
  •   Peder Rice    14 年前

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

        3
  •  1
  •   Arsen Mkrtchyan    15 年前

    它可能还小吗?您是否试图给出更大的值,比如655360000?请注意,您应该更改客户机和服务器配置文件中的值。我猜你只在一个方面改变了;)

        4
  •  1
  •   leppie    15 年前

    从谷歌的一个小搜索中,你似乎是在错误的地方添加了设置。

    你需要创建一个新的 behavior endPointBehaviors 部分(不是) serviceBehaviors )

        5
  •  1
  •   babukorrapati    13 年前

    我也有同样的问题。在类级别使用服务行为属性很好,这是有意义的。我更喜欢配置级别的更改。我添加了客户端(web.config)和服务级别(app.config)的配置条目。这对你有用吗?