WCF service - MaxReceivedMessageSize property

Posted on 2012-09-20
Last Modified: 2012-10-10
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."
Question by:5281
    LVL 14

    Assisted Solution

    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


    Author Comment

    I added your second sample into web.config file, but it still gave that same error message when I invoke the WCF server.
    LVL 11

    Expert Comment

    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.

    Author Comment


    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.
    LVL 11

    Expert Comment

    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.

    Author Comment

    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 1.1 web application, how to specify the setting in a 1.1 application?
    LVL 11

    Accepted Solution

    Ok, that explains a little bit. Unfortunately I haven't tried to use WCF with anything below an 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.

    Author Comment


    The code you provide about MaxReceivedMessageSize, should it be put in WCF service application or consuming application?

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now