Xml/Xslt - Increase the maxarraylengh property

Asked By prince b on 03-Oct-11 05:26 AM
How to increase the MaxArrayLength property
on the XmlDictionaryReaderQuotas object
Reena Jain replied to prince b on 03-Oct-11 05:30 AM
HI,

It was an IIS configuration that needs to be added to the Web.config file on the server side of the WCF service as follows:

<system.web>
<httpRuntime
executionTimeout="1200"
maxRequestLength="102400"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100" />
....

The specific problem was with the maxRequestLength defaulting to about 4 Mg in IIS. Apparently the values configured in WCF don't override IIS. You still need the httpRuntime configuration above.

Sakshi a replied to prince b on 03-Oct-11 05:31 AM

if wcf then u can do so as in ,

http://stackoverflow.com/questions/688988/configuring-a-web-service-endpoint-and-contract-from-c-code
Chintan Vaghela replied to prince b on 03-Oct-11 05:40 AM
Hello there,

This can look quite confusing if you are not familiar with how WCF Channel pipeline works. This error is encountered by many even if you are not using GZipEncoder outlined above. So let’s look at all solutions while using & not using GzipEncoder (below I set the limit to max allowed, though it’s not recommended) :
 
1) Standard Binding (No GZipEncoder)
<bindings>
    <basicHttpBinding>
    <binding>
      <readerQuotas maxStringContentLength=”2147483647″/>
    </binding>
    </basicHttpBinding>
</bindings>
//new BasicHttpBinding().ReaderQuotas.MaxStringContentLength = Int32.MaxValue
N.B. Binding is a collection of channels providing an abstract way to add readerQuotas.
 
2) Custom Binding (No GZipEncoder)
<bindings>
    <customBinding>
    <binding>
      <textMessageEncoding>
      <readerQuotas maxStringContentLength=”2147483647″/>
      </textMessageEncoding>
      <httpTransport />
    </binding>
    </customBinding>
</bindings>
 
/*
CustomBinding binding = new CustomBinding();
TextMessageEncodingBindingElement element = new TextMessageEncodingBindingElement();
element.ReaderQuotas.MaxStringContentLength = Int32.MaxValue;
binding.Elements.Add(element);
*/
N.B. For CustomBinding you need to select channels manually and for encoding channel you can specify the readerQuotas.
 
3) Using GZipEncoder – in this case you need to add couple of lines in GZipMessageEncodingBindingElement class (GZipMessageEncodingBindingElement.cs file). The method which you would change is below:
 
public override IChannelFactory BuildChannelFactory (BindingContext context)
{
if (context == null)
throw new ArgumentNullException(“context”);
context.BindingParameters.Add(this);
 
var property = GetProperty<XmlDictionaryReaderQuotas>(context);
property.MaxStringContentLength = 2147483647; //Int32.MaxValue
property.MaxArrayLength = 2147483647;
property.MaxBytesPerRead = 2147483647;
 
return context.BuildInnerChannelFactory();
}
 
N.B. It’s not possible to alter these parameters through configuration file while using GZipEncoder.
 
Hope this helps :) .
Suchit shah replied to prince b on 03-Oct-11 05:49 AM
XmlDictionaryReaderQuotas.MaxArrayLength Property

Gets and sets the maximum allowed array length.
http://msdn.microsoft.com/en-us/library/ms366772(v=VS.85)
http://msdn.microsoft.com/en-us/library/system.xml.xmldictionaryreaderquotas.maxarraylength.aspx