Where to put MaxReceivedMessageSize property in WCF service's web.config file?

I need to change my web.config file and add the MaxReceivedMessageSize property in my web.config - but where?

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.

   <?xml version="1.0"?>
        <compilation debug="false"><assemblies><add assembly="System.Data.Entity, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" /></assemblies></compilation>
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
        <modules runAllManagedModulesForAllRequests="true" />


You need to define a binding configuration for the binding you want to use and then you need to define your services (on the server-side) and clients (on the client side) to use that binding and binding configuration:

      <!-- pick whichever binding you want .... -->
         <!-- binding configuration with a name -->
         <binding name="ExtendedMaxSize"  
             maxBufferSize="999999" maxReceivedMessageSize="999999" />
    <service name="Yournamespace.YourServiceClass" behaviorConfiguration="...">
      <!-- define endpoint with your binding and the name of the binding configuration
           that you have defined just above -->
      <endpoint address=""
                contract="Yournamespace.IYourServiceContract" />

To help those who may end up here like I did. I cannot add to the comments above yet (Usually someone already has the answers long before I have the problem), so I have to add an answer.

I have an MVC 4 app, and I suspect the initial sample above is from the web.config of the actual WCF service project. One of the comments mentions they suspect it is an MVC 4 app and the default config settings.

But how do you fix the problem? From more research, it appears that the change actually needs to be made to the web.config for the CLIENT, in other words, the web config for the project with the REFERENCE to the WCF service. You will find it is much easier to make the change there. That version of the web.config will actually resemble what you are looking for.

That worked easily for me and fixed my issue.

  1. No need, contrary to often claimed, to set on the server.
  2. Contrary to what MSDN is saying, it is not enough to set the limit on the transport binding element. Need to set on binding itself too. For example:

var targetBinding = new BasicHttpsBinding();

targetBinding.MaxReceivedMessageSize = MaxWcfMessageSize;
targetBinding.MaxBufferPoolSize = MaxWcfMessageSize;
targetBinding.MaxBufferSize = MaxWcfMessageSize;

var targetBindingElements = targetBinding.CreateBindingElements();
var httpsBindElement = targetBindingElements.Find<HttpsTransportBindingElement>();

httpsBindElement.MaxReceivedMessageSize = MaxWcfMessageSize;
httpsBindElement.MaxBufferPoolSize = MaxWcfMessageSize;
httpsBindElement.MaxBufferSize = MaxWcfMessageSize;

TextMessageEncodingBindingElement tmbebe = targetBindingElements.Find<TextMessageEncodingBindingElement>();
tmbebe.ReaderQuotas.MaxArrayLength = MaxWcfMessageSize;

Need Your Help

WPF DataGrid : CanContentScroll property causing odd behavior

wpf binding wpfdatagrid

i have a solution where i generate a DataGrid (or multiple instances) based on user criteria.. each grid keeps receiving data as it comes in via ObservableCollection