3

I know this has been asked a few times, but I tried all the solutions on stackoverfolow and none of them seemed to work so here it goes :

I have a service (running on NetTCP binding) which just waits for connections and assigns work to another service when called, the data it passes is huge and thus I am recieveing this error :

Maximum number of items that can be serialized or deserialized in an object graph is '65536'”

below is my config :

<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>

As you can see in my CoreTcpBinding I have pretty much maxed out all configuration values but I still keep getting the same error, I'm just stumped as to why does it default to "65536" ?

The service (client) that calls the above defined service has the following configuration:

<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>

The client talks to the Server via proxy as usual :

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;           

        }
Murtaza Mandvi
  • 10,708
  • 23
  • 74
  • 109
  • I see that in your server config the endpoint contract attribute is not a fully qualified name. Make sure that it is fully qualified(i.e. needs to have the namespace before the interface name) – Rajesh Sep 18 '12 at 09:36
  • http://stackoverflow.com/questions/7476853/wcf-error-maximum-number-of-items-that-can-be-serialized-or-deserialized-in-an – Uğur Gümüşhan Jan 30 '13 at 07:39

1 Answers1

3

You have to configure this at client and server side. Make sure you have the dataContractSerializer maxItemsInObjectGraph="2147483647" at both sides.

Peter
  • 27,590
  • 8
  • 64
  • 84
  • Both sides being very important – Christoph Sep 17 '12 at 15:07
  • If you check above I have added the client service config above which contains maxItemsInObjectGraph="2147483647" - still the same error. – Murtaza Mandvi Sep 17 '12 at 15:20
  • 1
    It seems that your "client-side" config isn't actually client-side. You have something that acts as both a client and a server, and you've only configured the server part of it in your 2nd config snippet. – Eugene Osovetsky Sep 19 '12 at 08:26