8

I've implemented a small set of REST services using WCF. One of the services recieves a large amount of data. When calling it (this is when runnig it from visual studio - I haven't deployed itto a production server yet) I get the error

The remote server returned an error: (413) Request Entity Too Large.

My web config

<binding name="BasicHttpBinding_ISalesOrderDataService" 
         closeTimeout="00:10:00"
         openTimeout="00:10:00" 
         receiveTimeout="00:10:00" 
         sendTimeout="00:10:00"
         allowCookies="false" 
         bypassProxyOnLocal="false" 
         hostNameComparisonMode="StrongWildcard"
         maxBufferPoolSize="2147483647" 
         maxBufferSize="2147483647" 
         maxReceivedMessageSize="2147483647"
         textEncoding="utf-8" 
         transferMode="Buffered" 
         useDefaultWebProxy="true"
         messageEncoding="Text">
  <readerQuotas maxDepth="2000000" 
                maxStringContentLength="2147483647"
                maxArrayLength="2147483647" 
                maxBytesPerRead="2147483647"
                maxNameTableCharCount="2147483647" />
  <security mode="None">
    <transport clientCredentialType="None" 
               proxyCredentialType="None" 
               realm="" />
    <message clientCredentialType="UserName" 
             algorithmSuite="Default" />
  </security>
</binding>
Tim
  • 28,212
  • 8
  • 63
  • 76
Rakin
  • 1,271
  • 14
  • 30
  • where are you hosting that? in IIS? – Daniel A. White Sep 30 '15 at 12:57
  • my data is only 20KB . when i convert object to JSON . – Rakin Sep 30 '15 at 13:32
  • In your **service** config, do you define the same binding, and did you assign that binding to an explicit endpoint? Can you post the `` section of your service's config? – Tim Sep 30 '15 at 17:40
  • In my code i dynamically change End Point URL. Will they effect? – Rakin Oct 01 '15 at 05:20
  • Pleae find the code below for changing endpoint dynamically `SalesOrderDataServiceClient _sodataservice = new SalesOrderDataServiceClient(); string[] EndPointURLSplitups = _sodataservice.Endpoint.Address.Uri.AbsoluteUri.Split('/'); _sodataservice.Endpoint.Address = new System.ServiceModel.EndpointAddress(new Uri(enpointurl + "/" + EndPointURLSplitups[EndPointURLSplitups.Length - 1]), _sodataservice.Endpoint.Address.Identity, _sodataservice.Endpoint.Address.Headers); _salesOrderDataService = _sodataservice;` – Rakin Oct 01 '15 at 05:23
  • Enable service tracing on server side. Post full stack trace. – jsanalytics Oct 07 '15 at 14:14
  • @jstreet how to enable it? – Rakin Oct 08 '15 at 04:54
  • [Configuring Tracing - MSDN](https://msdn.microsoft.com/en-us/library/ms733025%28v=vs.110%29.aspx) – jsanalytics Oct 08 '15 at 05:02
  • And then inspect it using [Service Trace Viewer Tool - MSDN](https://msdn.microsoft.com/en-us/library/ms732023%28v=vs.110%29.aspx) – jsanalytics Oct 08 '15 at 05:10
  • Server stack trace: at `System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory`1 factory, WebException responseException, ChannelBinding channelBinding) at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)` – Rakin Oct 09 '15 at 06:35
  • @Rakin - the code you posted for calling he service is code for making a SOAP call, not a REST call. Please post the complete `` section from your Web.config file, as well as the complete code you're using to call the service. This is a **very** common issue and there are a number of reasons you can be encountering it, but without more information the answers provided will be a guessing game. – Tim Oct 14 '15 at 05:43

7 Answers7

4

Seem you exceed quota augment those value.

 maxReceivedMessageSize="2000000" maxBufferSize="2000000">

(or review your query for a lower result when possible)

if nothing work check here its like comon probleme.

The remote server returned an error: (413) Request Entity Too Large

Community
  • 1
  • 1
Zwan
  • 632
  • 2
  • 6
  • 23
  • earlier i used 2000000 .. changed to 2147483647 when i see some articles related to this – Rakin Sep 30 '15 at 13:23
3

I'm afraid your client is fine but you need to check the server web.config

add value the same way you did for your client

<bindings>
      <basicHttpBinding>
        <binding maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Text">
          <readerQuotas maxDepth="2000000" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </basicHttpBinding>
</bindings>
Zwan
  • 632
  • 2
  • 6
  • 23
3

In addition to increasing message size and buffer size quotes, consider also increase maxItemsInObjectGraph for serializer. It can matter if your object has complex structure or array of objects inside. Our typical setting look so

 <behaviors>
  <endpointBehaviors>
    <behavior name="GlobalEndpoint">
      <dataContractSerializer maxItemsInObjectGraph="1365536" />
    </behavior>
 </behaviors>
 <serviceBehaviors>
    <behavior name="GlobalBehavior">
      <dataContractSerializer maxItemsInObjectGraph="1365536" />
    </behavior>
 </serviceBehaviors>

And additionaly what Zwan has proposed

Mimas
  • 525
  • 3
  • 7
2

If I understand you correctly your request is the one that is delivering large amounts of data. That means that you have to edit the maxRecievedMessageSize like @Zwan have written. Not in the client's config but in the rest services config to allow big requests of data.

2

Try increasing the "maxItemsInObjectGraph" size in web.config file, as this change worked for me.For details please see.

Sachin Gaikwad
  • 331
  • 3
  • 10
  • 2
    For details please see.(https://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractserializer.maxitemsinobjectgraph(v=vs.110).aspx) – Sachin Gaikwad Oct 14 '15 at 04:24
1

If you host the wcf rest service in a asp.net application, the httpRuntime limits must also be set because wcf service is running in ASP .NET compatibilty mode. Note that maxRequestLength has value in kilobytes

<configuration> <system.web>
<httpRuntime maxRequestLength="10240" /> </system.web> </configuration>

Refer at The remote server returned an error: (413) Request Entity Too Large

More advice should make Dispose, destructor for services

[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession, ConcurrencyMode = ConcurrencyMode.Multiple, MaxItemsInObjectGraph = 2147483647)]
[GlobalErrorBehaviorAttribute(typeof(GlobalErrorHandler))]
public partial class YourService : IYourService
{

    // Flag: Has Dispose already been called? 
    bool disposed = false;
    // Instantiate a SafeHandle instance.
    SafeHandle handle = new SafeFileHandle(IntPtr.Zero, true);

    // Public implementation of Dispose pattern callable by consumers. 
    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }

    // Protected implementation of Dispose pattern. 
    protected virtual void Dispose(bool disposing)
    {
        if (disposed)
            return;

        if (disposing)
        {
            handle.Dispose();
            // Free any other managed objects here. 
            //
        }

        // Free any unmanaged objects here. 
        //
        disposed = true;
    }

    ~YourService()  // destructor
    {
      Dispose();
    }

}

Hope it helps!

Lewis Hai
  • 1,114
  • 10
  • 22
1

Since ok with maxRecievedMessageSize, you can check "IIS Request Filtering" where maximum length of content in a request, in bytes

Also in the IIS – “UploadReadAheadSize” that prevents upload and download of data greater than 49KB. The value present by default is 49152 bytes and can be increased up to 4 GB.

Josh
  • 1,009
  • 2
  • 13
  • 25