(413) Request entity too large

I have a WCF service, and I have a method when I want to pass a parameter as a large string (more than 1 mb)

I run this wcf, and in the WCF test client I changed the configuration as shown below:

<?xml version="1.0" encoding="utf-8"?> <configuration> <system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IMyService" sendTimeout="00:05:00" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" /> </binding> </basicHttpBinding> </bindings> 

And when I try to call this method, I still have 413 request objects too large.

+5
source share
2 answers

As Matt Burland suggested, you need to configure the end of the service as well as the client. See Configuring services using configuration files for more information . The task is not much different from what you did on the client side. Here is an excerpt from the above article.

WCF uses the System.Configuration for .NET. Framework When configuring a service in Visual Studio, use either the Web.config file or the App.config file to specify options. The choice of the configuration file name is determined by the hosting environment that you choose for maintenance. If you use IIS to host your service, use the Web.config file. If you use other hosting, use the App.config file.

I would suggest not installing everything on int.MaxValue , since MaxReceivedMessageSize set to 2 GB, it opens you up to DOS (Denial-Of-Service), etc. The comments section of the MaxReceivedMessageSize property equals:

The size of messages that can be received in a wired service using WSHttpBindingBase is limited by the amount of memory allocated for each message. This message size limit is intended to limit the susceptibility of denial of service (DoS) attacks.

You might just try to get it to work at this point, but it is far from recommended that you leave it that way.

+4
source

I also ran into the same problem and solved the problem. Work Code -

(413) Request entity too much in WCF Follow app.config code. This works and with this I can send a large file

 <bindings> <webHttpBinding> <binding name="myBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647" transferMode="Streamed" > <readerQuotas maxDepth="64" maxArrayLength="2147483647" maxStringContentLength="2147483647"/> </binding> </webHttpBinding> </bindings> <services> <service behaviorConfiguration="ForecastREST_API.RESTServiceImplBehavior" name="ForecastREST_API.RestServiceImpl"> <endpoint address="http://localhost:59624/RestServiceImpl.svc" binding="webHttpBinding" contract="ForecastREST_API.IRestServiceImpl" behaviorConfiguration="Web" bindingConfiguration="myBinding"> </identity> </endpoint> <endpoint address="mex" binding="webHttpBinding" contract="IMetadataExchange"/> </service> </services> <behaviors> <endpointBehaviors> <behavior name="Web"> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> <webHttp defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" /> <dispatcherSynchronization asynchronousSendEnabled="true" /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="ForecastREST_API.RESTServiceImplBehavior"> <dataContractSerializer maxItemsInObjectGraph="2147483647" /> <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> 
+4
source

Source: https://habr.com/ru/post/1206124/


All Articles