WCF Error "Maximum number of items that can be serialized or deserialized in an object graph is '65536'"
Asked Answered
R

5

14

I am receiving the following error on a WCF call:

Maximum number of items that can be serialized or deserialized in an object graph is '65536'

I've read a ton of forum posts and many of them mention modifying the app.config and web.config to specify new behavior to allow larger object graphs. I've done that and this is what I have in those files:

App.Config on the WPF project:

<system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="false" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="">
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
    </behavior>

  </endpointBehaviors>

</behaviors>

<services>
  <service name="digiPM.Shell.LogOutPMSEMRService.PMSEMRLogOutService">
    <!--<endpoint address="" binding="basicHttpBinding" contract="digiPM.Shell.LogOutPMSEMRService.IPMSEMRLogOutService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8732/Design_Time_Addresses/digiPM.Shell.LogOutPMSEMRService/PMSEMRLogOutService/" />
      </baseAddresses>
    </host>-->
    <endpoint address="" binding="netTcpBinding" name="NetTcpBindingEndpoint" contract="digiPM.Shell.LogOutPMSEMRService.IPMSEMRLogOutService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" name="MexTcpBidingEndpoint" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="net.tcp://localhost:8732/Design_Time_Addresses/digiPM.Shell.LogOutPMSEMRService/PMSEMRLogOutService/" />
      </baseAddresses>
    </host>
  </service>
</services>

<!--binding info - removed this for the sake of readability for this post -->

web.config on the service project:

<system.serviceModel>

<bindings>
  <wsHttpBinding>
      <binding name="WSHttpBinding_Services" closeTimeout="01:10:00" openTimeout="01:10:00" receiveTimeout="01:10:00" sendTimeout="01:10:00" bypassProxyOnLocal="false" 
               transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647" 
               messageEncoding="Mtom" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="4096" maxStringContentLength="2147483647" maxArrayLength="524288" maxBytesPerRead="524288" maxNameTableCharCount="524288" />
          <reliableSession ordered="true" inactivityTimeout="01:10:00" enabled="false" />

          <security mode="None">

          </security>
      </binding>
  </wsHttpBinding>
</bindings>

<behaviors>
  <serviceBehaviors>
    <behavior name="digiPM.Service.Behavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
      <dataContractSerializer maxItemsInObjectGraph="2147483647" />
    </behavior>

  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="customObjectQuota">
      <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
    </behavior>
  </endpointBehaviors>
</behaviors>

<services>
  <service behaviorConfiguration="digiPM.Service.Behavior"
    name="digiPM.Service.AddressCrudService">
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_Services"
                name="AddressCrudServiceEndPoint" bindingNamespace="urn:Dawliasoft.Sculpture"  contract="digiPM.Services.Contracts.IAddressCrudService" behaviorConfiguration="customObjectQuota" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"  behaviorConfiguration="customObjectQuota" />
  </service>

 <!--<more services defined with same configuration as above..>-->

  </services>


</system.serviceModel>

This, however, hasn't helped. Note that the services referenced in the APP.CONFIG are not the services I am having issues with.

I've also tried the following:

  • added these attributes to the service implementation: [DataContract(IsReference=true)], [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any, MaxItemsInObjectGraph = 2147483646)]

  • wrote a custom DataContractSerializerOperationBehavior class that set MaximumObjectsInGraph and IsReference behavior. Also added custom Attribute to apply this the service implementations. For the sake of clutter, I didn't post the code, but can add it if anyone thinks it would be beneficial.

Thoughts? Ideas? Where do I go from here?

Thanks in advance!

Ravelment answered 19/9, 2011 at 20:22 Comment(0)
B
4

I just realized that your WPF config file is not right. So, I deleted all my comments because they were assuming a valid WCF configuration. Your WPF config file is not right ... it needs to say "Client" instead of service ... Are you using "Add Service Reference" in Visual Studio? if so, it should have created the correct config file for you.

Otherwise, please refer to MSDN for the correct format for your client config file in your WPF project.

Bloodthirsty answered 19/9, 2011 at 20:34 Comment(3)
i added more from system.service model sections from both config filesRavelment
aha!... i think you may be on to something... I'll check out adding the "Client" section. FYI - this is a project I inherited from another team, I have no idea what method they used generate the app.config file for the WPF app.Ravelment
Please try adding a "Service Reference" in visual studio and don't forget to delete the entire "system.servicemodel" section in your app.config before adding your service reference ... your life will be a lot easier ... and then you can customize your config file by adding the 'maxItemsInObjectGraph' stuff ... good luck.Bloodthirsty
C
16

Configuring the below values solved the problem for me.

Client Config:

<system.serviceModel>
<bindings>
<basicHttpBinding>
  <binding name="BasicHttpBinding_IManagementService" closeTimeout="00:01:00"
    openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
    allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
    maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647"
    messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
    useDefaultWebProxy="true">
    <readerQuotas maxDepth="128" maxStringContentLength="2147483647"
      maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
    <security mode="None">
      <transport clientCredentialType="None" proxyCredentialType="None"
        realm="" />
      <message clientCredentialType="UserName" algorithmSuite="Default" />
    </security>
  </binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://XXXX/ManagementService.svc"
  binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IManagementService"
  contract="ManagementServiceReference.IManagementService"
  name="BasicHttpBinding_IManagementService" behaviorConfiguration="ManagementServiceBehaviour"/>
</client>
<behaviors>
<endpointBehaviors>
  <behavior name="ManagementServiceBehaviour">
    <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
  </behavior>
</endpointBehaviors>
</behaviors>

Server Config:

<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<behaviors>
<serviceBehaviors>
  <behavior name="ManagementServiceBehaviour">
    <serviceDebug includeExceptionDetailInFaults="true" />
    <serviceMetadata httpGetEnabled="true" />
    <dataContractSerializer ignoreExtensionDataObject="false" maxItemsInObjectGraph="2147483646" />
  </behavior>
  <behavior name="">
    <serviceMetadata httpGetEnabled="true" />
    <serviceDebug includeExceptionDetailInFaults="false" />
  </behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
  <binding name="BasicHttpBinding" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" closeTimeout="01:50:00" openTimeout="01:50:00" sendTimeout="01:50:00" receiveTimeout="01:50:00" >
    <readerQuotas maxDepth="128" maxStringContentLength="8388608" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
  </binding>
</basicHttpBinding>
</bindings>

<services>
<service behaviorConfiguration="ManagementServiceBehaviour" name="BusinessLogic.Facade.EntityFacade.Services.ManagementService">
  <endpoint binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding" contract="BusinessLogic.Facade.EntityFacade.Contracts.IManagementService">
    <identity>
      <dns value="" />
    </identity>
  </endpoint>
</service>
</services>
</system.serviceModel>
Christcross answered 28/12, 2011 at 13:17 Comment(1)
Hi, i try to use your code (binding and behaviour but i get this error message : Content Type text/xml; charset=utf-8 was not supported by service. Do you have any clue why i get this error message?Siegfried
B
6

Have you tried upping the buffer and max received message size as well?

maxBufferSize="6553600" maxBufferPoolSize="52428800" maxReceivedMessageSize="6553600"
Bemused answered 19/9, 2011 at 20:26 Comment(6)
Would this go in the web.config of the service host project? or the app.config of the client? or both?Ravelment
on the app.config of the application.Bemused
this is uncharted territory for me... :-) is this the right approach? <bindings> <basicHttpBinding> <binding maxBufferPoolSize="2147483646" maxBufferSize="2147483646" maxReceivedMessageSize="2147483646" /> </basicHttpBinding> </bindings>Ravelment
i added your suggestion to the app.config of the app, and it did not seem to make a differenceRavelment
This line resolved the issue, but Ram got the +1 because he told us where to put itBalcke
Oddly, the following code doesn't work, but putting this in the app.config did (where hcs is my service...I'm using asmx...yes, I know...) ((System.ServiceModel.HttpBindingBase)hcs.Endpoint.Binding).MaxReceivedMessageSize = Int32.MaxValue;((System.ServiceModel.HttpBindingBase)hcs.Endpoint.Binding).MaxBufferSize = Int32.MaxValue; ((System.ServiceModel.HttpBindingBase)hcs.Endpoint.Binding).MaxBufferPoolSize = Int32.MaxValue;Towns
B
4

I just realized that your WPF config file is not right. So, I deleted all my comments because they were assuming a valid WCF configuration. Your WPF config file is not right ... it needs to say "Client" instead of service ... Are you using "Add Service Reference" in Visual Studio? if so, it should have created the correct config file for you.

Otherwise, please refer to MSDN for the correct format for your client config file in your WPF project.

Bloodthirsty answered 19/9, 2011 at 20:34 Comment(3)
i added more from system.service model sections from both config filesRavelment
aha!... i think you may be on to something... I'll check out adding the "Client" section. FYI - this is a project I inherited from another team, I have no idea what method they used generate the app.config file for the WPF app.Ravelment
Please try adding a "Service Reference" in visual studio and don't forget to delete the entire "system.servicemodel" section in your app.config before adding your service reference ... your life will be a lot easier ... and then you can customize your config file by adding the 'maxItemsInObjectGraph' stuff ... good luck.Bloodthirsty
A
1

Beware of the "dataContractSerializer" element. In my case I got the error mentioned until I put this element as the first item of the parent element "behavior". At least on the client side indeed.

Anschluss answered 21/8, 2013 at 12:52 Comment(0)
H
0

You are returning a generic list or an array which has a size of more than 65536. in your queries, using a select top 60000 or not adding more than 60k elements will solve your problem.

Hannan answered 30/1, 2013 at 7:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.