what is <readerQuotas> in WCF Binding?

PramodChoudhari picture PramodChoudhari · Jun 6, 2011 · Viewed 10.7k times · Source

I gone through this MSDN link but could not get enough details

Can any one explain me with a scenario where and why i need to set this value.

I came across the setting when i was trying to send a Data Contract object to service method and was getting exception The remote server returned an error: Not Found.,

My data contract is having List<>property and was getting exception if list contains 7 object it was working fine with 6 object.

I guess it was issue with Size of Data Contract.

When i changed my binding in config file

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

to

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

the Data Contract object reached to Service for processing.

Answer

Smudge202 picture Smudge202 · Jun 6, 2011

The readerQuota settings are used to limit bindings as specified by the attributes. If a request exceeds any of those limits the WCF service will automatically reject the request (very low on the comms stack I believe) to do as little processing on the request as is possible.

The idea being that the service commit as few resources as possible to service the request (if it exceeds a given limit) to help fend off Denial-of-Service attacks - DDOS.

Note that the readQuota limits can be set on both server and client. This allows clients to be protected against fraudulent servers as well as protecting the servers.