Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to increase MaxReceivedMessageSize when calling a WCF from C# [duplicate]

Tags:

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

I am using WCF for file uploading and downloading. uploading is successful but when i downloading a large file i found this error

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.

My Service.config file has the following code.

<system.web>     <compilation debug="true" />     <httpRuntime executionTimeout="4800" maxRequestLength="2147483647" />     </system.web>   <system.serviceModel>     <bindings>       <basicHttpBinding>         <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferPoolSize="524288">           <readerQuotas maxDepth="32" maxStringContentLength="2147483647"              maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"  />         </binding>       </basicHttpBinding>       <!--<webHttpBinding>         <binding maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" />       </webHttpBinding>-->     </bindings>     <services>       <service name="WITSService.WITSService">         <clear />         <endpoint binding="basicHttpBinding" contract="WITSService.WITSService" />       </service>     </services>      <behaviors>       <serviceBehaviors>         <behavior>           <serviceMetadata httpGetEnabled="true"/>           <serviceDebug includeExceptionDetailInFaults="false"/>           <dataContractSerializer maxItemsInObjectGraph="2147483646"/>         </behavior>       </serviceBehaviors>       <endpointBehaviors>         <behavior name="myEndPointBehavior">           <dataContractSerializer maxItemsInObjectGraph="2147483646"/>         </behavior>       </endpointBehaviors>     </behaviors>      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />   </system.serviceModel> 

can any one help me how to increase MaxReceivedMessageSize

like image 385
MindFresher Avatar asked Jan 03 '13 06:01

MindFresher


People also ask

How do you increase MaxReceivedMessageSize?

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.

What is the default MaxReceivedMessageSize for WCF service?

By default, it is 65536.

What is the MaxReceivedMessageSize WCF max value?

MaxReceivedMessageSize = 1000000; The value of this property can also be set in the configuration file.


2 Answers

Change the customBinding in the web.config to use larger defaults. I picked 2MB as it is a reasonable size. Of course setting it to 2GB (as your code suggests) will work but it does leave you more vulnerable to attacks. Pick a size that is larger than your largest request but isn't overly large.

Check this : Using Large Message Requests in Silverlight with WCF

<system.serviceModel>    <behaviors>      <serviceBehaviors>        <behavior name="TestLargeWCF.Web.MyServiceBehavior">          <serviceMetadata httpGetEnabled="true"/>          <serviceDebug includeExceptionDetailInFaults="false"/>        </behavior>      </serviceBehaviors>    </behaviors>    <bindings>      <customBinding>        <binding name="customBinding0">          <binaryMessageEncoding />          <!-- Start change -->          <httpTransport maxReceivedMessageSize="2097152"                         maxBufferSize="2097152"                         maxBufferPoolSize="2097152"/>          <!-- Stop change -->        </binding>      </customBinding>    </bindings>    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>    <services>      <service behaviorConfiguration="Web.MyServiceBehavior" name="TestLargeWCF.Web.MyService">        <endpoint address=""                 binding="customBinding"                 bindingConfiguration="customBinding0"                 contract="TestLargeWCF.Web.MyService"/>        <endpoint address="mex"                 binding="mexHttpBinding"                 contract="IMetadataExchange"/>      </service>    </services>  </system.serviceModel>  
like image 127
Pranay Rana Avatar answered Nov 01 '22 04:11

Pranay Rana


You need to set basicHttpBinding -> MaxReceivedMessageSize in the client configuration.

like image 38
Tilak Avatar answered Nov 01 '22 04:11

Tilak