【问题标题】:WCF “Maximum number of items that can be serialized or deserialized in an object graph is '65536'”WCF“对象图中可以序列化或反序列化的最大项目数是'65536'”
【发布时间】:2012-09-09 19:06:44
【问题描述】:

我知道这个问题已经被问过几次了,但是我在 stackoverfolow 上尝试了所有的解决方案,但似乎没有一个有效,所以就这样吧:

我有一个服务(在 NetTCP 绑定上运行),它只是等待连接并在调用时将工作分配给另一个服务,它传递的数据很大,因此我收到此错误:

对象图中可以序列化或反序列化的最大项目数是'65536'”

下面是我的配置:

<services>
    <service behaviorConfiguration="CoreBehavior" name="PrepService">
        <endpoint address="net.tcp://localhost/Preparation" 
                  binding="netTcpBinding" 
                  contract="IWorkManagerService"
                  bindingConfiguration="CoreTcpBinding"/>            
    </service>
</services>
<bindings>
    <netTcpBinding>
        <binding name="CoreTcpBinding" closeTimeout="00:10:00" openTimeout="00:10:00"
                 sendTimeout="00:10:00" maxBufferSize="2147483647"
                 maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="64" maxStringContentLength="2147483647"
                 maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            <security mode="None"/>
        </binding>          
    </netTcpBinding>
</bindings>    
<behaviors>
    <serviceBehaviors>
        <behavior name="CoreBehavior">
            <serviceMetadata httpGetEnabled="false"  />
            <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
            <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
    </serviceBehaviors>
</behaviors>

正如您在我的 CoreTcpBinding 中看到的那样,我几乎已将所有配置值最大化,但我仍然不断收到相同的错误,我只是不明白为什么它默认为“65536”?

调用上面定义的服务的服务(客户端)有如下配置:

<services>
        <service behaviorConfiguration="CoreBehavior" name="AssignmentService">
         <endpoint address="net.tcp://localhost:8001/Assignment"
                          binding="netTcpBinding"
                          contract="IWorkerService" 
                          bindingConfiguration="CoreTcpBinding"/>
          </service>
 </services> 

            <bindings>
                <netTcpBinding>
                    <binding name="CoreTcpBinding" 
                             maxBufferPoolSize="2147483647"
                             maxReceivedMessageSize="2147483647">                  
                        <security mode="None"/>                 
                    </binding>
                </netTcpBinding>
            </bindings>
            <behaviors>        
                <serviceBehaviors>
                    <behavior name="CoreBehavior">
                        <dataContractSerializer maxItemsInObjectGraph="2147483647" />
                        <serviceDebug includeExceptionDetailInFaults="true"/>
                    </behavior>
                </serviceBehaviors>
            </behaviors>

客户端像往常一样通过代理与服务器对话:

var proxy = new PrepServiceProxy(new NetTcpBinding(), new EndpointAddress(ServiceAddress));

Proxy Code : 
 public PrepServiceProxy(Binding binding, EndpointAddress remoteAddress) : base(binding, remoteAddress)
        {            
            var netTcpBinding = binding as NetTcpBinding;

            if (netTcpBinding != null)
                (netTcpBinding).Security.Mode = SecurityMode.None;           

        }

【问题讨论】:

  • 我看到在您的服务器配置中,端点合同属性不是完全限定名称。确保它是完全限定的(即需要在接口名称之前有命名空间)

标签: wcf datacontractserializer


【解决方案1】:

您必须在客户端和服务器端进行配置。确保两边都有 dataContractSerializer maxItemsInObjectGraph="2147483647"。

【讨论】:

  • 双方都很重要
  • 如果你检查上面我已经添加了上面包含 maxItemsInObjectGraph="2147483647" 的客户端服务配置 - 仍然是同样的错误。
  • 看来您的“客户端”配置实际上并不是客户端。你有一个既作为客户端又作为服务器的东西,你只在你的第二个配置 sn-p 中配置了它的服务器部分。
猜你喜欢
  • 1970-01-01
  • 2011-11-20
  • 1970-01-01
  • 2018-09-26
  • 2013-06-21
  • 1970-01-01
  • 2012-02-29
  • 1970-01-01
相关资源
最近更新 更多