January 24, 2019

WCF - Set nametable character count quota

If you are receiving large size of string from WCF service, you may encounter maximum quota exceeding error.

The maximum nametable character count quota (16384) has been exceeded while reading XML data. The nametable is a data structure used to store strings encountered 
during XML processing – long XML documents with non-repeating element names, attribute names and attribute values may trigger this quota. This quota may be increased by changing 
the MaxNameTableCharCount property on the XmlDictionaryReaderQuotas object used when creating the XML reader. 

To fix this issue you have to change readerQuotas settings in the binding tag.

<binding> 
 <readerQuotas 
        maxDepth="2147483647" 
        maxStringContentLength="2147483647"
        maxArrayLength="2147483647" 
        maxBytesPerRead="4096"
        maxNameTableCharCount="2147483647"
        maxStringContentLength="2147483647"
  />
</binding>

The readerQuota settings are used to limit the bindings. If a request exceeds any of these limits the WCF service will automatically reject the request, to help prevent Denial-of-Service (DoS) attacks.

The readQuota limits can be set on both server and client. This also allows clients to be protected against forged service responses.

I hope this helps some of you who get stuck with a similar problem.

No comments:

Post a Comment