Search code examples
c#wcf

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"?>
   <configuration>
      <system.web>
        <compilation debug="false"><assemblies><add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /></assemblies></compilation>
      </system.web>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true" />
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
      </system.serviceModel>
     <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
      </system.webServer>

Solution

  • 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:

    <system.serviceModel>
       <bindings>
          <!-- pick whichever binding you want .... -->
          <basicHttpBinding>
             <!-- binding configuration with a name -->
             <binding name="ExtendedMaxSize"  
                 maxBufferSize="999999" maxReceivedMessageSize="999999" />
          </basicHttpBinding>
      </bindings>
      <services>
        <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=""
                    binding="basicHttpBinding"
                    bindingConfiguration="ExtendedMaxSize"  
                    contract="Yournamespace.IYourServiceContract" />
        </service>
      </services>