Search
Close this search box.

WCF maxStringContentLength, maxBufferSize, and MaxReceivedMessageSize

Today I discovered the some configuration impacts from my choice to return the XML document as a string property.  Because I am using a string property to return the XML generated by my service (see yesterday’s post) I had to adjust three properties in the service and client configuration.

MaxBufferSize property – (From MSDN) Gets or sets the maximum size of the buffer to use. For buffered messages this value is the same as MaxReceivedMessageSize. For streamed messages, this value is the maximum size of the SOAP headers, which must be read in buffered mode.

I went ahead and bumped that up to about 5MB which should be plenty for the messages I’m sending. Default is 65536.

MaxReceivedMessageSize must also match what you put in the MaxBufferSize.  Default is 65536.

MaxStringContentLength – (From MSDN) Gets and sets the maximum string length returned by the reader. Default is 8192.

This one I also bumped up to 5MB.  This property actually belongs to the XMLReader that is called under the covers by WCF.  When deserializing the message this property is used to block messages over a certain size.

All three appear for several reason I’m sure but the one that jumps out is security.  See “Security Considerations for Data” for more info on what those properties can prevent.

There are configuration elements for all three of these in the new WCF config tool.

Screens:

Right click on an app.config and choose “Edit WCF Configuration”

The highlighted areas are the properties I changed.

These have been posted on several other forums, blogs, etc, but I put this out there in case someone stumbles across it.

This article is part of the GWB Archives. Original Author: Niemguy

Related Posts