9 comments on “How to Set MaxItemsInObjectGraph Programmatically for Client

  1. Not sure where I got this, but another way to add a client behavior using the existing configuration behavior is as follows:
    BehaviorsSection behaviorsSection = configGroup.Sections[“behaviors”] as BehaviorsSection;
    if (behaviorsSection != null && !string.IsNullOrEmpty(behaviorConfiguration))
    EndpointBehaviorElement endPointBehaviorElement = behaviorsSection.EndpointBehaviors[behaviorConfiguration];
    if (endPointBehaviorElement != null && endPointBehaviorElement.Count > 0)
    // Loop the behavior extensions and call CreateBehavior
    foreach (BehaviorExtensionElement behaviorExtensionElement in endPointBehaviorElement)
    DataContractSerializerElement datacontractSerializerElement = behaviorExtensionElement as DataContractSerializerElement;
    if (datacontractSerializerElement is DataContractSerializerElement)
    // Get CreateBehavior method using Reflection because it is a protected internal virtual method
    MethodInfo createBehaviorMethodInfo = typeof(BehaviorExtensionElement).GetMethod(
    “CreateBehavior”, BindingFlags.Instance | BindingFlags.NonPublic);

    _endpointBehavior = (IEndpointBehavior)createBehaviorMethodInfo.Invoke(behaviorExtensionElement, null);



  2. Strange. When I have a look at These in the Debugger it tells me MaxItemsInObjectGraph already was int.MaxValue. Both on the client and the server side.

    So why do I get the same error as you did? Weird.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s