title: WCF Error "Maximum number of items that can be serialized or deserialized in an object graph is '65536'"
body: <p>I am receiving the following error on a WCF call:</p>
  
  <blockquote>
    <p>Maximum number of items that can be serialized or deserialized in an
    object graph is '65536'</p>
  </blockquote>
  
  <p>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:</p>
  
  <p><strong>App.Config on the WPF project:</strong></p>
  
  <pre><code>&lt;system.serviceModel&gt;
  &lt;behaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior name=""&gt;
        &lt;serviceMetadata httpGetEnabled="false" /&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt;
      &lt;/behavior&gt;
    &lt;/serviceBehaviors&gt;
    &lt;endpointBehaviors&gt;
      &lt;behavior name=""&gt;
        &lt;dataContractSerializer maxItemsInObjectGraph="2147483646"/&gt;
      &lt;/behavior&gt;
  
    &lt;/endpointBehaviors&gt;
  
  &lt;/behaviors&gt;
  
  &lt;services&gt;
    &lt;service name="digiPM.Shell.LogOutPMSEMRService.PMSEMRLogOutService"&gt;
      &lt;!--&lt;endpoint address="" binding="basicHttpBinding" contract="digiPM.Shell.LogOutPMSEMRService.IPMSEMRLogOutService"&gt;
        &lt;identity&gt;
          &lt;dns value="localhost" /&gt;
        &lt;/identity&gt;
      &lt;/endpoint&gt;
      &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /&gt;
      &lt;host&gt;
        &lt;baseAddresses&gt;
          &lt;add baseAddress="http://localhost:8732/Design_Time_Addresses/digiPM.Shell.LogOutPMSEMRService/PMSEMRLogOutService/" /&gt;
        &lt;/baseAddresses&gt;
      &lt;/host&gt;--&gt;
      &lt;endpoint address="" binding="netTcpBinding" name="NetTcpBindingEndpoint" contract="digiPM.Shell.LogOutPMSEMRService.IPMSEMRLogOutService"&gt;
        &lt;identity&gt;
          &lt;dns value="localhost" /&gt;
        &lt;/identity&gt;
      &lt;/endpoint&gt;
      &lt;endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" name="MexTcpBidingEndpoint" contract="IMetadataExchange" /&gt;
      &lt;host&gt;
        &lt;baseAddresses&gt;
          &lt;add baseAddress="net.tcp://localhost:8732/Design_Time_Addresses/digiPM.Shell.LogOutPMSEMRService/PMSEMRLogOutService/" /&gt;
        &lt;/baseAddresses&gt;
      &lt;/host&gt;
    &lt;/service&gt;
  &lt;/services&gt;
  
  &lt;!--binding info - removed this for the sake of readability for this post --&gt;
  </code></pre>
  
  <p><strong>web.config on the service project:</strong></p>
  
  <pre><code>&lt;system.serviceModel&gt;
  
  &lt;bindings&gt;
    &lt;wsHttpBinding&gt;
        &lt;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"&gt;
            &lt;readerQuotas maxDepth="4096" maxStringContentLength="2147483647" maxArrayLength="524288" maxBytesPerRead="524288" maxNameTableCharCount="524288" /&gt;
            &lt;reliableSession ordered="true" inactivityTimeout="01:10:00" enabled="false" /&gt;
  
            &lt;security mode="None"&gt;
  
            &lt;/security&gt;
        &lt;/binding&gt;
    &lt;/wsHttpBinding&gt;
  &lt;/bindings&gt;
  
  &lt;behaviors&gt;
    &lt;serviceBehaviors&gt;
      &lt;behavior name="digiPM.Service.Behavior"&gt;
        &lt;serviceMetadata httpGetEnabled="true" /&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="false" /&gt;
        &lt;dataContractSerializer maxItemsInObjectGraph="2147483647" /&gt;
      &lt;/behavior&gt;
  
    &lt;/serviceBehaviors&gt;
    &lt;endpointBehaviors&gt;
      &lt;behavior name="customObjectQuota"&gt;
        &lt;dataContractSerializer maxItemsInObjectGraph="2147483646"/&gt;
      &lt;/behavior&gt;
    &lt;/endpointBehaviors&gt;
  &lt;/behaviors&gt;
  
  &lt;services&gt;
    &lt;service behaviorConfiguration="digiPM.Service.Behavior"
      name="digiPM.Service.AddressCrudService"&gt;
      &lt;endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_Services"
                  name="AddressCrudServiceEndPoint" bindingNamespace="urn:Dawliasoft.Sculpture"  contract="digiPM.Services.Contracts.IAddressCrudService" behaviorConfiguration="customObjectQuota" /&gt;
      &lt;endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"  behaviorConfiguration="customObjectQuota" /&gt;
    &lt;/service&gt;
  
   &lt;!--&lt;more services defined with same configuration as above..&gt;--&gt;
  
    &lt;/services&gt;
  
  
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>This, however, hasn't helped.  Note that the services referenced in the APP.CONFIG are not the services I am having issues with.</p>
  
  <p>I've also tried the following:</p>
  
  <ul>
  <li><p>added these attributes to the service implementation: [DataContract(IsReference=true)], [ServiceBehavior(AddressFilterMode = AddressFilterMode.Any, MaxItemsInObjectGraph = 2147483646)]</p></li>
  <li><p>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.</p></li>
  </ul>
  
  <p>Thoughts? Ideas? Where do I go from here?</p>
  
  <p>Thanks in advance!</p>