Why do I still get "The maximum message size quota for incoming messages (65536) has been exceeded" error?

StackOverflow https://stackoverflow.com/questions/21096327

  •  27-09-2022
  •  | 
  •  

Question

I'm encountering the well-known WCF error:

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.

After reading the top five Google results for this error, I still haven't any clue about what could be wrong with the configuration of my service/client.

What I have tried:

  1. Setting maxReceivedMessageSize.

  2. Setting maxBufferSize and maxBufferPoolSize.

  3. Adding readerQuotas.

  4. Ensuring the values are the same for the client and the server..

  5. Ensuring binding configuration is specified by name.

  6. Including the namespace in the service name.

Note that:

  • Small messages are transmitted correctly, but the error above occurs when sending a large message from the client to the server.

  • The message which is too large contains a ≈350 KB byte array (given that WCF is configured to encode to base64 the binary data).

  • It's a (1) two-way communication which (2) uses net TCP binding with (3) reliable session and (4) ordering set on (those four points differ from every example I've seen searching for the error).

  • The service is hosted by IIS Express installed with Visual Studio 2012.

This is my configuration. Any hint?

<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
                           multipleSiteBindingsEnabled="true" />
<bindings>
  <netTcpBinding>
    <binding name="netTcpEndpoint"
             receiveTimeout="00:10:00"
             sendTimeout="00:10:00"
             maxBufferSize="2147483647"
             maxReceivedMessageSize="2147483647"
             maxBufferPoolSize="2147483647">
      <readerQuotas maxDepth="2147483647"
                    maxArrayLength="2147483647"
                    maxStringContentLength="2147483647"
                    maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647"/>
      <reliableSession ordered="true"
                       inactivityTimeout="00:10:00"
                       enabled="false" />
      <security mode="None">
        <message clientCredentialType="None" />
      </security>
    </binding>
  </netTcpBinding>
</bindings>
<services>
  <service behaviorConfiguration="DebugOrientedBehavior"
           name="DemoNamespace.PipeService">
    <endpoint address="Default.svc"
              binding="netHttpBinding"
              name="TransportLayerServiceEndpoint"
              contract="DemoNamespace.IPipeService" />
    <host>
      <baseAddresses>
        <add baseAddress="http://example.com/Default.svc" />
      </baseAddresses>
    </host>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="DebugOrientedBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

The client configuration is this one:

<bindings>
  <netHttpBinding>
    <binding name="TransportLayerServiceEndpoint"
             receiveTimeout="00:10:00"
             sendTimeout="00:10:00"
             maxBufferPoolSize="2147483647"
             maxBufferSize="2147483647"
             maxReceivedMessageSize="2147483647">
      <readerQuotas maxDepth="2147483647"
                    maxArrayLength="2147483647"
                    maxStringContentLength="2147483647"
                    maxBytesPerRead="2147483647"
                    maxNameTableCharCount="2147483647"/>
      <reliableSession ordered="true"
                       enabled="false" />
      <webSocketSettings transportUsage="Always" />
    </binding>
  </netHttpBinding>
</bindings>
<client>
  <endpoint address="ws://example.com/Default.svc/Default.svc"
            binding="netHttpBinding"
            bindingConfiguration="TransportLayerServiceEndpoint"
            contract="PipeServiceReference.IPipeService"
            name="TransportLayerServiceEndpoint" />
</client>
Was it helpful?

Solution

Your service config appears to have an issue - you specify netHttpBinding for the service endpoint with no bindingConfiguration, and you have a configuration defined for netTcpBinding (but apparently not used). Relevant service portion of your config here:

<endpoint address="Default.svc"
          binding="netHttpBinding"
          name="TransportLayerServiceEndpoint"
          contract="DemoNamespace.IPipeService" />

Note that there is no bindingConfiguration value set. I would suggest adding the binding configuration defined in the client to your service config, and then updating the service endpoint to use that binding:

<endpoint address="Default.svc"
          binding="netHttpBinding"
          bindingConfiguration="TransportLayerServiceEndpoint"
          name="TransportLayerServiceEndpoint"
          contract="DemoNamespace.IPipeService" />

Currently your service is using the default values for netHttpBinding, which is probably the reason you're still getting the error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top