Set maxitemsinobjectgraph in client config [from stackflow]

Source: Internet
Author: User

I am specifying maxitemsinobjectgraph in the server config file but while creating client config file, this attribute is ignored and I have to manually add it in the endpointbehaviors section.

Is there a way I can make some changes in the config file so that everytime I generate client config and proxy via svcutil.exe, this behaviour is automatically inserted in the client config file?

I tried ading[ServiceBehavior(MaxItemsInObjectGraph = 2147483647)]To 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.

 

 

No, that is another behavior which is configured per participant ipant. Each client has control over this property and service doesn't expose this property because it cocould be considered as security issue.

If your problem is mainly about development (where you don't want to modify your behavior every time you refresh the reference) You can usecommonBehaviorsSection which can be defined only in machine. config:

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

Common behaviors are added to every service/Endpoint running on the machine. it is perhaps good for development but you mustn't forget that once you will prepare package for production you will have to add this configuration to production's config file-because of that it is better to maintain such configuration file continuously and use it on some build/test server.

 

 

 

 

Behaviors are typically local settings (you can have different values for client and server, and the communication can still work out fine ), so they're not exposed in WSDL (and so svcutil will not be able to find that value ).

You have basically 2 choices: update the client config every time you generate, or in code, when you create an instance of the proxy class, update the miiog property, similar to the code below.

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

Note that if you are handwriting the client implementation instead of using auto-generated stubs, the endpoint is available through the channelfactory used to create the channel for the Service Interface

 

From: http://stackoverflow.com/questions/6283037/set-maxitemsinobjectgraph-in-client-config

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.