WCF Service Configuration for basicHttpBinding

Rob McCabe picture Rob McCabe · Jun 13, 2013 · Viewed 8k times · Source

I am having an issue where I have SOA with a web site consuming services and a web site hosting services. One of my services accepts an image (byte[]). When I pass an image of 83kb to the WCF service I get the following error:

The maximum array length quota (16384) has been exceeded while reading XML data. This quota may be increased by changing the MaxArrayLength property on the XmlDictionaryReaderQuotas object used when creating the XML reader.

There is no specific config in my server side configuration for this service. The following is in my consuming web application web.config file:

<system.serviceModel>
    <bindings>
      <basicHttpBinding>
          <binding name="BasicHttpBinding_ISchoolSettings" 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="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="false">
          <readerQuotas maxDepth="32" maxStringContentLength="998192" maxArrayLength="2147483647" maxBytesPerRead="4096" maxNameTableCharCount="2147483647" />
          <security mode="None">
            <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:50977/Interface/Schools.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISchoolSettings" contract="Services.Schools.ISchoolSettings" name="BasicHttpBinding_ISchoolSettings" />
    </client>
  </system.serviceModel>

It looks like .net is ignoring the fact I've set MaxArrayLength=2147483647 for this binding configuration.

I am using .net 4.0 here. Curiously, I have a machine with .net 4.5 on it and I DONT get this error on that machine!!

I've tried all sorts but cant seem to get around this issue.

Answer

Sixto Saez picture Sixto Saez · Jun 13, 2013

Make sure you change the setting on both the client config and the service config. It can be a bit confusing sometimes to see where the exception is actually occurring.