none
WCF maxItemsInObjectGraph config does not work when hosted inside IIS RRS feed

  • Question

  • I have 2 project one is called "Service" and is of type "WCF Service Library" the other one is called "Service.Hosting" and is of type "WCF Service Application" The Service.Hosting project is just used for hosting the IService1 which is defined in the Service project.

    I have a method defined in IService1 which is called GetAll() and should return all employees in the database.

    Both in Service/App.config and Service.Hosting/Web.config i have defined teh behaviour

    <dataContractSerializer maxItemsInObjectGraph="2147483646"/>

    inside of

    <behaviors>
      <serviceBehaviors>
        <behavior>

    When i run the solution from inside of Visual Studio, i will get two endpoints, one from the Serviceproject hostet through WCF Service Host and one from the Service.Hosting project hosted in IIS Express.

    Now im using the WCF Test Client to call GetAll() on both endpoints. I have declared maxItemsInObjectGraph="2147483646" in the WCF Test Client in the endpointBehavior.

    When I'm calling GetAll() on the Service endpoint hosted in WCF Service Host, everything is fine. When I'm calling GetAll() on the Service.Hosting endpoint hosted in IIS Express, I get this exeption:

    System.Runtime.Serialization.SerializationException Die maximale Anzahl der Elemente in einem Objektgraph, die serialisiert bzw. deserialisiert werden können, beträgt "32767". Ändern Sie den Objektgraph oder erhöhen Sie das MaxItemsInObjectGraph-Kontingent.

    What I have tried so far: Giving the behaviour a name and explicitly assigning it. Adding it to my Service using an Attribute.

    Does anyone know what a can do to fix this?

    Here is are the full configs:

    Service/App.config

      <system.serviceModel>
        <bindings />
        <client />
        <services>
          <service name="Senacor.Employee.EmployeeMasterData.Service.Service1">
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:8733/Design_Time_Addresses/Senacor.Employee.EmployeeMasterDataService/Service1/" />
              </baseAddresses>
            </host>
            <!-- Service Endpoints -->
            <!-- Unless fully qualified, address is relative to base address supplied above -->
            <endpoint address="" binding="basicHttpBinding" contract="Senacor.Employee.EmployeeMasterData.Service.IService1">
              <!-- 
                  Upon deployment, the following identity element should be removed or replaced to reflect the 
                  identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
                  automatically.
              -->
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
            <!-- Metadata Endpoints -->
            <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
            <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information, 
              set the values below to false before deployment -->
              <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
              <!-- To receive exception details in faults for debugging purposes, 
              set the value below to true.  Set to false before deployment 
              to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="True" />
              <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>

    Service.Hosting/Web.config

      <system.serviceModel>
        <extensions>
          <behaviorExtensions>
            <add name="formsAuthentication" type="WcfServerExtensions.FormsAuthenticationBehaviorExtensionElement, WcfServerExtensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
          </behaviorExtensions>
        </extensions>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
              <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
              <serviceDebug includeExceptionDetailInFaults="true" />
              <dataContractSerializer maxItemsInObjectGraph="2147483646"/>
            </behavior>
          </serviceBehaviors>
          <endpointBehaviors>
            <behavior>
              <formsAuthentication />
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <bindings>
          <basicHttpBinding>
            <binding closeTimeout="Infinite" openTimeout="Infinite" receiveTimeout="Infinite" sendTimeout="Infinite" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
            </binding>
          </basicHttpBinding>
        </bindings>
        <protocolMapping>
            <add binding="basicHttpsBinding" scheme="https" />
        </protocolMapping>    
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
      </system.serviceModel>

    Service.Hosting/Service1.svc

    <%@ ServiceHost Language="C#" Debug="true" Service="Senacor.Employee.EmployeeMasterData.Service.Service1" %>
    <%@ Assembly Name="Senacor.Employee.EmployeeMasterData.Service" %>
    Tuesday, March 10, 2015 8:36 AM

Answers

All replies

  • Hi wertzui,

    I see that you have configured the service with a large value for the maxItemsInObjectGraph in the Service.Hosting/Web.config. But have you configured the maxItemsInObjectGraph in the client side as well? If you do not configure it, it will throw exception when reach the limit value. So please try to make sure that you have the following configuration in the client side:

    <behaviors> 
        <endpointBehaviors> 
            <behavior name="MyEndpointBehavior"> 
                <dataContractSerializer maxItemsInObjectGraph="2147483646" /> 
            </behavior> 
        </endpointBehaviors> 
    </behaviors>
    
    <client> 
        <endpoint address="***"
            behaviorConfiguration="MyEndpointBehavior" 
            binding="basicHttpBinding" bindingConfiguration="***" 
            contract="***" name="***" /> 
    </client>

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Wednesday, March 11, 2015 5:23 AM
    Moderator
  • Hi Amy,

    yes, I did configure the client as well.

    Wednesday, March 11, 2015 7:49 AM
  • http://blogs.msdn.com/b/kaevans/archive/2008/01/24/wcf-and-custom-bindings.aspx

    I don't see you using Custom Binding on the service side to override default settings.

    Wednesday, March 11, 2015 3:08 PM