首页 文章

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

提问于
浏览
3

我知道这已被问过几次了,但是我尝试了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;           

        }

1 回答

  • 3

    您必须在客户端和服务器端配置它 . 确保两侧都有dataContractSerializer maxItemsInObjectGraph =“2147483647” .

相关问题