WCF service doesn’t accept files over 64 KB

Published May 25 2021 01:32 PM 3,215 Views
Microsoft

While trying to upload files that are bigger than 64 KB, we came across this error: 413 Request Entity Too Large.

 

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.

 

 

 

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.

 

As the error above mentions, this issue occurs because the request size is bigger than the MaxReceivedMessageSize for WCF.

 

Solution

Increase MaxReceivedMessageSize value for your web service to solve this issue. However, this may get tricky because there are two different MaxReceivedMessageSize parameters:

  • MaxReceivedMessageSize in System.ServiceModel.Configuration.BasicHttpBindingElement
  • MaxReceivedMessageSize in System.ServiceModel.Channels.HttpTransportBindingElement

 

This configuration below will increase the MaxReceivedMessageSize in System.ServiceModel.Configuration.BasicHttpBindingElement

 

<basicHttpBinding>
   <binding name="basicHttpBinding_Portal" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
       <readerQuotas maxBytesPerRead="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647"/>
    </binding>
</basicHttpBinding>

 

 

 

You should increase the MaxReceivedMessageSize in System.ServiceModel.Channels.HttpTransportBindingElement as well:

 

<customBinding>
   <binding closeTimeout="00:10:00" openTimeout="00:10:00" sendTimeout="00:10:00">
      <httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" useDefaultWebProxy="true" transferMode="Buffered" />
   </binding>
</customBinding>

 

 

You can also do it in the code as explained in this document.

%3CLINGO-SUB%20id%3D%22lingo-sub-2385315%22%20slang%3D%22en-US%22%3EWCF%20service%20doesn%E2%80%99t%20accept%20files%20over%2064%20KB%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2385315%22%20slang%3D%22en-US%22%3E%3CP%3EWhile%20trying%20to%20upload%20files%20that%20are%20bigger%20than%2064%20KB%2C%20we%20came%20across%20this%20error%3A%20413%20Request%20Entity%20Too%20Large.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3EThe%20maximum%20message%20size%20quota%20for%20incoming%20messages%20(65536)%20has%20been%20exceeded.%20To%20increase%20the%20quota%2C%20use%20the%20MaxReceivedMessageSize%20property%20on%20the%20appropriate%20binding%20element.%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20maximum%20message%20size%20quota%20for%20incoming%20messages%20(65536)%20has%20been%20exceeded.%20To%20increase%20the%20quota%2C%20use%20the%3CCODE%3EMaxReceivedMessageSize%3C%2FCODE%3Eproperty%20on%20the%20appropriate%20binding%20element.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20the%20error%20above%20mentions%2C%20this%20issue%20occurs%20because%20the%20request%20size%20is%20bigger%20than%20the%3CCODE%3EMaxReceivedMessageSize%3C%2FCODE%3Efor%20WCF.%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-2033851608%22%20id%3D%22toc-hId-2033851581%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22toc-hId-226397145%22%20id%3D%22toc-hId-226397118%22%3E%3CSTRONG%3ESolution%20%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3EIncrease%3CCODE%3EMaxReceivedMessageSize%3C%2FCODE%3Evalue%20for%20your%20web%20service%20to%20solve%20this%20issue.%20However%2C%20this%20may%20get%20tricky%20because%20there%20are%20two%20different%3CCODE%3EMaxReceivedMessageSize%3C%2FCODE%3Eparameters%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EMaxReceivedMessageSize%20in%20System.ServiceModel.Configuration.%3CSTRONG%3EBasicHttpBindingElement%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EMaxReceivedMessageSize%20in%20System.ServiceModel.Channels.%3CSTRONG%3EHttpTransportBindingElement%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20configuration%20below%20will%20increase%20the%3CCODE%3EMaxReceivedMessageSize%3C%2FCODE%3Ein%20System.ServiceModel.Configuration.%3CSTRONG%3EBasicHttpBindingElement%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E%3CBASICHTTPBINDING%3E%0A%20%20%20%3CBINDING%20name%3D%22basicHttpBinding_Portal%22%20maxreceivedmessagesize%3D%222147483647%22%20maxbuffersize%3D%222147483647%22%20maxbufferpoolsize%3D%222147483647%22%3E%0A%20%20%20%20%20%20%20%3CREADERQUOTAS%20maxbytesperread%3D%222147483647%22%20maxarraylength%3D%222147483647%22%20maxstringcontentlength%3D%222147483647%22%20maxdepth%3D%222147483647%22%20maxnametablecharcount%3D%222147483647%22%3E%3C%2FREADERQUOTAS%3E%0A%20%20%20%20%3C%2FBINDING%3E%0A%3C%2FBASICHTTPBINDING%3E%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20should%20increase%20the%3CCODE%3EMaxReceivedMessageSize%3C%2FCODE%3Ein%20System.ServiceModel.Channels.%3CSTRONG%3EHttpTransportBindingElement%3C%2FSTRONG%3E%26nbsp%3Bas%20well%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-html%22%3E%3CCODE%3E%3CCUSTOMBINDING%3E%0A%20%20%20%3CBINDING%20closetimeout%3D%2200%3A10%3A00%22%20opentimeout%3D%2200%3A10%3A00%22%20sendtimeout%3D%2200%3A10%3A00%22%3E%0A%20%20%20%20%20%20%3CHTTPTRANSPORT%20maxreceivedmessagesize%3D%222147483647%22%20maxbuffersize%3D%222147483647%22%20usedefaultwebproxy%3D%22true%22%20transfermode%3D%22Buffered%22%3E%3C%2FHTTPTRANSPORT%3E%0A%20%20%20%3C%2FBINDING%3E%0A%3C%2FCUSTOMBINDING%3E%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20also%20do%20it%20in%20the%20code%20as%20explained%20in%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Fsystem.servicemodel.channels.httptransportbindingelement%3Fview%3Ddotnet-plat-ext-5.0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ethis%20document%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎May 25 2021 01:35 PM
Updated by: