Default Quoting in WCF

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

By transferring of messages sometimes one message can contain the data which exceeds some limits, which are internally defined by WCF.

In such cases you will possible get some error messages which look like following one:

 

Test method xxxxx threw exception: System.ServiceModel.ProtocolException: The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://mynamespace/2007/09:BinaryData. The InnerException message was 'There was an error deserializing the object of type System.Byte[]. 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. Line 1, position 48255.'. Please see InnerException for more details.

To avoid such errors, you have to be aware of following:
Serialization of objects in WCF is a process internally based on XmlDictionarySerializer. The size of some important internal values is limited to usual business cases. For example, by transmitting of binary data, the size of maximal array is limited to 16384 (0x4000) bytes. Another "frequently exceeding" value is the maximal size of one string etc.

 

All these values are controlled by the class XmlDictionaryReaderQuotas. Here is the definition of all default limits:

 

private const int DefaultMaxArrayLength = 0x4000;

private const int DefaultMaxBytesPerRead = 0x1000;

private const int DefaultMaxDepth = 0x20;

private const int DefaultMaxNameTableCharCount = 0x4000;

private const int DefaultMaxStringContentLength = 0x2000;

 

The good thing is that these values can be changed. The usual way to do that is manipulating of the configuration file. Following example shows how to do that:

<configuration>

 

<system.serviceModel>

 

<bindings>

<basicHttpBinding>

<binding name="BasicHttpBinding_IMulltiPersService" closeTimeout="00:01:00"

openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"

allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"

maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"

messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"

useDefaultWebProxy="true">

<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"

maxBytesPerRead="4096" maxNameTableCharCount="48000" />


Posted Sep 03 2007, 03:12 PM by Damir Dobric
Filed under:
developers.de is a .Net Community Blog powered by daenet GmbH.