none
WCF message too big even with correct web.config RRS feed

  • Question

  • I have a WCF service with the following web.config:

    <?xml version="1.0"?>
    <configuration>
      <system.serviceModel>
        <behaviors>
          <serviceBehaviors>
            <behavior name="MetadataExchange">
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="True"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <bindings>
          <basicHttpBinding>
            <binding name="LargeHttpBinding" maxBufferSize="5064536" maxBufferPoolSize="5064536" maxReceivedMessageSize="5064536">
              <readerQuotas maxDepth="32" maxStringContentLength="5064536" maxArrayLength="5064536" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            </binding>
          </basicHttpBinding>
        </bindings>
        <services>
          <service behaviorConfiguration="MetadataExchange" name="Service.Interface.ApplicationService.ApplicationService">
            <endpoint name="httpEndpoint" address="" binding="basicHttpBinding" bindingConfiguration="LargeHttpBinding" contract="Service.Proxy.ApplicationService.Interfaces.IApplicationService" />
            <endpoint name="mexEndpoint" address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange"/>
            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:15000/"/>
              </baseAddresses>
            </host>
          </service>
        </services>
        <client>
          <endpoint name="httpEndpoint" address="http://localhost:15000/ApplicationService/ApplicationService.svc" binding="basicHttpBinding" bindingConfiguration="LargeHttpBinding" contract="Service.Proxy.ApplicationService.Interfaces.IApplicationService" />
        </client>
      </system.serviceModel>
      <system.webServer>
        <!--ToDo: Set directory browse to false-->
        <directoryBrowse enabled="true"/>
        <validation validateIntegratedModeConfiguration="false"/>
      </system.webServer>
    </configuration>

    The service should be able to receive 5MB+Overhead messages (I send pictures as byte arrays to the server).

    On the client side i use a ChannelFactory with the following BasicHttpBinding:

    basicHttpBinding = new BasicHttpBinding();
    basicHttpBinding.MaxBufferSize = 5064536;
    basicHttpBinding.MaxBufferPoolSize = 5064536;
    basicHttpBinding.MaxReceivedMessageSize = 5064536;
    basicHttpBinding.ReaderQuotas.MaxDepth = 32;
    basicHttpBinding.ReaderQuotas.MaxStringContentLength = 5064536;
    basicHttpBinding.ReaderQuotas.MaxArrayLength = 5064536;
    basicHttpBinding.ReaderQuotas.MaxBytesPerRead = 4096;
    basicHttpBinding.ReaderQuotas.MaxNameTableCharCount = 16384;

    If i try to send pictures with a size of about 150kb a error message is thrown with the following message:

    The remote server returned an unexpected response: (413) Request Entity Too Large
    Saturday, December 26, 2015 2:51 PM

Answers

  • I am an idiot. I tested my service with a 1920*1080 image with 167kb. Then I converted the picture to a byte[] (~2,000,000 pixels multiplied by 4 (a, r, g, b)) and then it had 8MB.

    How can I delete this question?

    Saturday, December 26, 2015 6:14 PM

All replies

  • Nothing in the service side config took affect and everything is still setting at their default settings on the bindings.

    You have to use custom bindings on the service side config to override default binding settings.

    http://www.dotnetfunda.com/articles/show/1047/how-to-create-custom-binding-in-wcf-services

    Saturday, December 26, 2015 4:56 PM
  • I created a binding configuration and added it to the endpoint. Shouldn't that be enough, because I don't want to create a custome binding if I can use the basicHttpBinding?

    If the configuration doesn't apply, what is the purpose of binding configurations?

    Saturday, December 26, 2015 5:19 PM
  • I am an idiot. I tested my service with a 1920*1080 image with 167kb. Then I converted the picture to a byte[] (~2,000,000 pixels multiplied by 4 (a, r, g, b)) and then it had 8MB.

    How can I delete this question?

    Saturday, December 26, 2015 6:14 PM
  • I created a binding configuration and added it to the endpoint. Shouldn't that be enough, because I don't want to create a custome binding if I can use the basicHttpBinding?

    If the configuration doesn't apply, what is the purpose of binding configurations?


    The custom binding is used to  override Readerquota and all that kind of stuff with the custom binding still using  basicHttpBinding.
    Saturday, December 26, 2015 6:21 PM