user1853786
user1853786

Reputation:

WCF The maximum message size quota for incoming messages (65536) has been exceeded

I am hoping you can help me as I have been tearing my hair out with this issue, having tried all solutions to this same question from the suggestions on this site and also via google to no avail. Among many others:

Wcf-The maximum message size quota for incoming messages (65536) has been exceeded?

WCF, The maximum message size quota for incoming messages (65536) has been exceeded

The maximum message size quota for incoming messages (65536) has been exceeded

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

As the title suggests I have an issue with the maximum message size for my incoming messages. I am trying to override the default message size but no matter what I attempt it does not work and the errors I receive tend to point to my custom configuration within the App.config file are not used instead of the default settings.

I am using WCF Service Host/WCF Test Client and Visual Studio 2017 Professional, my client project is a class library for a wider WPF MVVM project. I have not copied the WCF Service to a test Server 2012/IIS installation yet as this should work in my development environment?

I am attempting to increase the maximum message size for AirplaneService only, leaving all other services at default settings.

My Client Side App.Config which I have in my class library client only:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /></startup><system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IAirplaneService" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"  />
        </binding>
        <binding name="BasicHttpBinding_ILicenceService" />
        <binding name="BasicHttpBinding_ICustomerService" />
        <binding name="BasicHttpBinding_IMembershipService" />
        <binding name="BasicHttpBinding_IPrefixService" />
        <binding name="BasicHttpBinding_ICountryService" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/AirplaneService/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAirplaneService"
        contract="AirplaneService.IAirplaneService" name="BasicHttpBinding_IAirplaneService" />
      <endpoint address="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/LicenceService/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ILicenceService"
        contract="LicenceService.ILicenceService" name="BasicHttpBinding_ILicenceService" />
      <endpoint address="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/CustomerService/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICustomerService"
        contract="CustomerService.ICustomerService" name="BasicHttpBinding_ICustomerService" />
      <endpoint address="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/MembershipService/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMembershipService"
        contract="MembershipService.IMembershipService" name="BasicHttpBinding_IMembershipService" />
      <endpoint address="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/PrefixService/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IPrefixService"
        contract="PrefixService.IPrefixService" name="BasicHttpBinding_IPrefixService" />
      <endpoint address="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/CountryService/"
        binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICountryService"
        contract="CountryService.ICountryService" name="BasicHttpBinding_ICountryService" />
    </client>
  </system.serviceModel>
</configuration>

I believe I need to only modify the client side App.Config as I do not wish to receive large messages at the service side. However, for completeness I have also added relevant bindings to my Service App.Config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="FlightSchoolEntities" connectionString="metadata=res://*/FlightSchoolModel.csdl|res://*/FlightSchoolModel.ssdl|res://*/FlightSchoolModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=xx.xx.xx.xx;initial catalog=FlightSchool;persist security info=True;user id=sa;password=xxxxxxxxxxxx;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="myBasicBinding" maxBufferSize="2147483647" maxBufferPoolSize="524288" maxReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="128" maxStringContentLength="2147483647" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        </binding>
      </basicHttpBinding>
    </bindings>
    <services>
      <service name="Flight_School.Service.CountryService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/CountryService/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="Flight_School.Service.ICountryService">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      <service name="Flight_School.Service.PrefixService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/PrefixService/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="Flight_School.Service.IPrefixService">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
      <service name="Flight_School.Service.MembershipService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/MembershipService/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="Flight_School.Service.IMembershipService">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      <service name="Flight_School.Service.CustomerService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/CustomerService/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="Flight_School.Service.ICustomerService">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      <service name="Flight_School.Service.LicenceService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/LicenceService/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" contract="Flight_School.Service.ILicenceService">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
      <service name="Flight_School.Service.AirplaneService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/AirplaneService/" />
          </baseAddresses>
        </host>
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="myBasicBinding" contract="Flight_School.Service.IAirplaneService">
          <!-- 
              Upon deployment, the following identity element should be removed or replaced to reflect the 
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity 
              automatically.
          -->
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <!-- Metadata Endpoints -->
        <!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
        <!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, 
          set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
          <!-- To receive exception details in faults for debugging purposes, 
          set the value below to true.  Set to false before deployment 
          to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

Running this I receive the following error:

System.ServiceModel.CommunicationException: '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.'

A snippet of code where the error occurs:

            using (AirplaneService.AirplaneServiceClient service = new AirplaneService.AirplaneServiceClient())
            {
                List<AirplaneService.Manufacturer> manufacturers = service.GetManufacturers();

If I limit my results in service->GetManufacturers() it returns a list of manufacturers as expected.

Every time I re-run my service I need to change the config in WCF Test Client but even after doing so I still receive the same error when running the project.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IAirplaneService" sendTimeout="00:05:00"
                    maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:8733/Design_Time_Addresses/Flight_School.Service/AirplaneService/"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAirplaneService"
                contract="IAirplaneService" name="BasicHttpBinding_IAirplaneService" />
        </client>
    </system.serviceModel>
</configuration>

Your help will be most appreciated and many thanks in advance.

Richard.

Upvotes: 2

Views: 3552

Answers (2)

user1853786
user1853786

Reputation:

Thanks to Rabban who pointed out I needed to add my custom binding to the .exe project App.config file it now works as expected. I had to manually add the WCF service bindings to the .exe project App.config file a week or so ago and between then and now I forgot all about that one. I have also removed the custom binding from the service project App.config as this isn't required as I don't want to send large data transfers to the service. Many thanks again.

Upvotes: 0

Ved Prakash Tiwari
Ved Prakash Tiwari

Reputation: 267

Add following to your binding.

 <bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IAirplaneServicer" allowCookies="true" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
      <readerQuotas maxDepth="32" maxArrayLength="2147483647" maxStringContentLength="2147483647" />
     </binding>
  </basicHttpBinding>
</bindings>

Upvotes: 3

Related Questions