MaxItemsInObjectGraph is ignored

I have a problem with a WCF service that is trying to serialize too much data. From the trace I get an error message stating that the maximum number of elements that can be serialized or non-sterilized is "65536", try increasing the quota of MaxItemsInObjectGraph.

So, I went and changed this value, but it is simply ignored (the error is the same, with the same number). All this is the server side. I am calling the service through wget at the moment.

My web configuration is as follows:

<system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="AlgoMap.Web.MapService.MapServiceBehavior"> <dataContractSerializer maxItemsInObjectGraph="131072" /> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <bindings> <customBinding> <binding name="customBinding0" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:02:00"> <binaryMessageEncoding> <readerQuotas maxDepth="64" maxStringContentLength="16384" maxArrayLength="16384" maxBytesPerRead="16384" maxNameTableCharCount="16384" /> </binaryMessageEncoding> <httpTransport /> </binding> </customBinding> </bindings> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> <services> <service behaviorConfiguration="AlgoMap.Web.MapService.MapServiceBehavior" name="AlgoMap.Web.MapService.MapService"> <endpoint address="" binding="customBinding" bindingConfiguration="customBinding0" contract="AlgoMap.Web.MapService.MapService" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> </system.serviceModel> 



Version 2 not working:

  <system.serviceModel> <behaviors> <endpointBehaviors> <behavior name="AlgoMap.Web.MapService.MapServiceEndpointBehavior"> <dataContractSerializer maxItemsInObjectGraph="131072" /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="AlgoMap.Web.MapService.MapServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <bindings> <customBinding> <binding name="customBinding0" closeTimeout="00:02:00" openTimeout="00:02:00" receiveTimeout="00:02:00"> <binaryMessageEncoding> <readerQuotas maxDepth="64" maxStringContentLength="16384" maxArrayLength="16384" maxBytesPerRead="16384" maxNameTableCharCount="16384" /> </binaryMessageEncoding> <httpTransport /> </binding> </customBinding> </bindings> <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> <services> <service behaviorConfiguration="AlgoMap.Web.MapService.MapServiceBehavior" name="AlgoMap.Web.MapService.MapService"> <endpoint address="" binding="customBinding" bindingConfiguration="customBinding0" contract="AlgoMap.Web.MapService.MapService" behaviorConfiguration="AlgoMap.Web.MapService.MapServiceEndpointBehavior" /> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" behaviorConfiguration="AlgoMap.Web.MapService.MapServiceEndpointBehavior" /> </service> </services> </system.serviceModel> 

Can anyone help? Thanks!!

+7
wcf
source share
5 answers

Any setting placed in web.config was happily ignored, I did not find out why. But I found a workaround, i.e. put MaxItemsInObjectGraph as a class decoration . This works flawlessly:

 // MyService.svc // using... namespace MyNamespace { [ServiceContract] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [ServiceBehavior(MaxItemsInObjectGraph = 65536000)] public class MyWebService { [OperationContract] [WebGet(UriTemplate = "tree/{sessionId}", ResponseFormat = WebMessageFormat.Json)] public MyData GetTree(string sessionId) { ... ... 
+10
source share

I came across this also, in my case, I forgot to put this parameter in the client.config file of the client.

+3
source share
Maybe he is still small? Have you tried to give great value, like 655360000? Please note that you must change the value in the client and server configuration files. I assume that you have changed in only one part;)
+1
source share

From a small google search, it seems like you're adding the setting to the wrong place.

You need to create a new behavior in the endPointBehaviors section (not serviceBehaviors ).

+1
source share

I have the same problem. Using the class-level service behavior attribute works fine, which makes sense. I prefer changing the configuration level. I added configuration entries both on the client (web.config) and on the service level (app.config). Did this work for you?

+1
source share

All Articles