Set maxItemsInObjectGraph in client configuration

I specify maxItemsInObjectGraph in the server configuration file, but when creating the client configuration file this attribute is ignored, and I need to manually add it to the endpointBehaviors section.

Is there a way to make some changes to the configuration file so that every time I create the client and proxy configuration via Svcutil.exe, this behavior is automatically included in the client configuration file?

I tried ading [ServiceBehavior(MaxItemsInObjectGraph = 2147483647)]for the service interface, but it gives me an error sayingAttribute 'ServiceBehavior' is not valid on this declaration type. It is only valid on 'class' declarations.

+5
source share
2 answers

, , . , , .

( , ), commonBehaviors, machine.config:

<commonBehaviors>
  <behaviors>
    <endpointBehaviors>
      <dataContractSerializer maxItemsInObjectGraph="..." />
    </endpointBehaviors>
  </behaviors>
</commonBehaviors>

/ , . , , , , , - - / .

+7

- , , ( , ), WSDL ( svcutil ).

2 : , , , MIIOG, .

ServiceClient client = new ServiceClient();
foreach (var operationDescription in client.Endpoint.Contract.Operations)
{
    DataContractSerializerOperationBehavior dcsob =
        operationDescription.Behaviors.Find<DataContractSerializerOperationBehavior>();
    if (dcsob != null)
    {
        dcsob.MaxItemsInObjectGraph = int.MaxValue;
    }
}

, , ChannelFactory, .

+8

All Articles