locked
How to set MaxItemsInObjectGraph on the CLIENT side RRS feed

  • Question

  • I am receiving the following error on the CLIENT side

    The formatter threw an exception while trying to deserialize the message: Error while trying to deserialize parameter http://tempuri.org/:RetrieveAllResult. Maximum number of items that can be serialized or deserialized in an object graph is '65536'. Change the object graph or increase the MaxItemsInObjectGraph quota.

    The data that I am returning is about 3.5 meg in size with an unknown number of objects ( I don't want to count them).  I had to on the SERVER side add

    [ServiceBehavior( ReturnUnknownExceptionsAsFaults = true, MaxItemsInObjectGraph = 300000 )]

    to allow the data to be serialized.  I am hosting the service in IIS.  On the client side I currently have

    // Create a proxy with given client endpoint configuration
    EndpointAddress address = new EndpointAddress( "http://localhost/Test/ServiceLookup.svc" );
    WSHttpBinding binding = new WSHttpBinding();
    binding.MaxReceivedMessageSize = 4 * 1024 * 1024;
    binding.ReaderQuotas.MaxArrayLength = 4 * 1024 * 1024;
    binding.ReaderQuotas.MaxBytesPerRead = 4 * 1024 * 1024;
     
    ChannelFactory<ILookup> factory = new ChannelFactory<ILookup>( binding, address );
    ILookup channel = factory.CreateChannel();
    lookup = channel.Retrieve();

    Any thoughts are appreciated on how to set MaxItemsInObjectGraph on the CLIENT side would be much appreciated.

    Cheers,

    Dave

     

     

    Tuesday, June 27, 2006 8:11 PM

Answers

All replies

  • You have to change this setting by using dataContractSerializer behaviour.

    <behaviors>

    <behavior name="CalculatorServiceBehavior">

    <dataContractSerializer maxItemsInObjectGraph="6553600" />

    </behavior>

    </behaviors>


    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=461822&SiteID=1

    Wednesday, June 28, 2006 1:03 PM
  • How would I get to it from here? 

    // Create a proxy with given client endpoint configuration
    EndpointAddress address = new EndpointAddress( "http://localhost/EventTest/ServiceLookup.svc" );
    WSHttpBinding binding = new WSHttpBinding();

    ChannelFactory<ILookup> factory = new ChannelFactory<ILookup>( binding, address );
    ILookup channel = factory.CreateChannel();

    Cheers,
    Dave

    Wednesday, June 28, 2006 3:01 PM
  • I think we have to implement this solution

    http://blogs.msdn.com/sowmy/archive/2006/03/26/561188.aspx

    Wednesday, June 28, 2006 8:40 PM
  • Hey guys I found a easier solution, a litlle bit later but it doesn't hurt:

     

    Fisrt you must add to your app.config servicemodel section an endpoint behavior:

     

    <behaviors>

    <endpointBehaviors>

    <behavior name="Graph">

    <dataContractSerializer maxItemsInObjectGraph="10000000"/>

    </behavior>

    </endpointBehaviors>

    </behaviors>

     

    Then at your endpoint you can reference it:

     

    <client>

    <endpoint address="http://localhost:8080/esService.svc"

    binding="customBinding" bindingConfiguration="wsNomina"

    contract="eSIPREN.Nomina" name="wsNomina" behaviorConfiguration="Graph">

    <identity>

    <userPrincipalName value="XlomasPCReload\Francisco Lomas" />

    </identity>

    </endpoint>

    </client>

     

     

    And voila!! It works!!! I guess that the solution at http://blogs.msdn.com/sowmy/archive/2006/03/26/561188.aspx must be the correct way, but I would like to ask: Is this resolved at WCF RTM??

    • Proposed as answer by bjpierson24 Tuesday, December 26, 2017 7:51 PM
    Friday, April 4, 2008 11:00 PM
  • Hi  FcoLomas

     

    Looks like your solution is the only working one.   Mucking around with all the other "accepted" answers got me no where.    I would mark yours as the answer, but looks like someone marked previous post instead.

     

    Cheers,

    Alex

    Wednesday, April 16, 2008 11:57 PM
  • I'm pleased that my answer helps, it doesn't matter if another is marked as the answer...

     

    Thursday, April 17, 2008 12:38 AM
  • I know this topic has been closed for some time, but I found an article which discusses how to do this in code:

     

    http://msdn.microsoft.com/en-us/library/ms732038.aspx

     

    Note that the Find() method has been replaced with an indexer by type.  Here is the corrected code:

     

    Channel Factory:

     

    Code Snippet

    foreach (OperationDescription op in _channelFactory.Endpoint.Contract.Operations)

    {

        DataContractSerializerOperationBehavior dataContractBehavior =

        op.Behaviors[typeof(DataContractSerializerOperationBehavior)]

        as DataContractSerializerOperationBehavior;

        if (dataContractBehavior != null)

        {

            dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;

        }

    }

     

     

    Service Host:

     

    Code Snippet

    foreach (ServiceEndpoint ep in host.Description.Endpoints)

    {

        foreach (OperationDescription op in ep.Contract.Operations)

        {

            DataContractSerializerOperationBehavior dataContractBehavior =

            op.Behaviors[typeof(DataContractSerializerOperationBehavior)]

            as DataContractSerializerOperationBehavior;

            if (dataContractBehavior != null)

            {

                dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;

            }

        }

    }

     

    • Proposed as answer by Francois Nel Friday, February 13, 2009 1:10 PM
    Wednesday, September 3, 2008 9:13 PM
  •  Finally, Doug you are an angel.

    I have been trying several hours now to implement a pure code client, and no information I had found up until now worked for me.
    This one did however!
    Tuesday, December 30, 2008 7:55 PM
    • Edited by Koen j Friday, April 13, 2012 10:04 AM url
    Friday, April 13, 2012 10:03 AM
  • YES! Thanks!

    On client I've this error on winxp, but in win7 no errors...

    i've implemented this code to client side and no errors any more! )))

    that solution worked for me! 

    Thursday, July 4, 2013 11:05 AM