WCF service - MaxReceivedMessageSize property

I got a message about MaxReceivedMessageSize, when I invoke a WCF service in WCF Test Client.  I think the dataset the Service return is bigger than others.  How to solve this problem?  Can you provide some sample code?

"Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service."

"The maximum message size quota for incoming messages (65536) has been exceeded. To increase the quota, use the MaxReceivedMessageSize property on the appropriate binding element."
Who is Participating?
Kelvin McDanielSr. Developer/ConsultantCommented:
Ok, that explains a little bit. Unfortunately I haven't tried to use WCF with anything below an asp.net 2.0 app, so my advice will be a little limited.

However, here is the portion of an older consuming app's web.config that sets the max received message size.

			<behavior name="">
				<serviceMetadata httpGetEnabled="true"/>
				<serviceDebug includeExceptionDetailInFaults="false"/>
			<binding name="BasicHttpBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="10240000" maxBufferPoolSize="81920000" maxReceivedMessageSize="10240000" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
				<readerQuotas maxDepth="32" maxStringContentLength="10240000" maxArrayLength="20480000" maxBytesPerRead="5120000" maxNameTableCharCount="20480000"/>
				<security mode="None">
					<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
					<message clientCredentialType="UserName" algorithmSuite="Default"/>
	<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>

Open in new window

The size in the code above is the most recent change we've had to make to acccomodate the same problem you're having.
Vel EousResearch & Development ManagerCommented:
You can increase the MaxReceivedMessageSize in code as follows:

var binding = new WsHttpBinding(); // replace this with your preferred binding
binding.MaxReceivedMessageSize = Int32.MaxValue * 4;
var WcfClient = new WcfService(binding, serviceUrl);

Open in new window

Or you can do it in the App.config file:

			<binding name="wsHttpBindingSettings" maxReceivedMessageSize="2147483647" />

Open in new window

5281Author Commented:
I added your second sample into web.config file, but it still gave that same error message when I invoke the WCF server.
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Kelvin McDanielSr. Developer/ConsultantCommented:
If I remember correctly (it's been a while) the same setting also needs to be on the client side and the value needs to match what's in the service definition.

I'd caution against using such a huge value... in effect, you're giving the "all clear" for the service to send back a 2GB message.
5281Author Commented:

Do you mean the same setting also needs to be on the server side?  I am working on my local IIS server (localhost), how can I change my localhost setting?

That service returns a dataset, I don't understand why it is called "message" here.
Kelvin McDanielSr. Developer/ConsultantCommented:
WCF services pass serialized strings, so the common term used across various technologies is "message". We are saying the same thing.  :)

Yes, the same setting needs to be on both the service website and the consuming website. They may be one in the same, so the section of the web.config that deals with each part needs to have the same setting.
5281Author Commented:
Do you mean I should ignore the error message gave in WCF Test Client?  It will be ok as long as both web.config files include above setting?  

My consuming website is not a wcf project, it is a regular asp.net 1.1 web application, how to specify the setting in a asp.net 1.1 application?
5281Author Commented:

The code you provide about MaxReceivedMessageSize, should it be put in WCF service application or consuming application?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.