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

  • Question

  • User-679965845 posted

    Hi

    I have created a WCF REST service

    This is my Service--

    [OperationContract]
     [WebInvoke(UriTemplate = "Test/", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
            public string Test(Stream notesStream)
            {
                try
                {
                    StreamReader NotesReader = new StreamReader(notesStream);
                    string NotesStr = NotesReader.ReadToEnd();
    JObject Gjsonformat = JObject.Parse(NotesStr);
                    string SemesterID = (string)Gjsonformat["SemesterID"];
                    string img = (string)Gjsonformat["Image"];
                    return "success";
                }
                catch (Exception ex)
                {
                    return ex.Message;
                }
            }

    I m passing semetserId as string and

    in Image i m passing base64 of an image.

    but it gives me an error "The remote server returned an error: (413) Request Entity Too Large. "

    I have included folllowing things in my web.config but the problem is intact.

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

    <system.webServer>
        <directoryBrowse enabled="false" />
        <modules runAllManagedModulesForAllRequests="true" />
        <defaultDocument>
          <files>
            <add value="index.aspx" />
          </files>
        </defaultDocument>
        <asp></asp>

        <serverRuntime uploadReadAheadSize="2147483647" maxRequestEntityAllowed="2147483647" enabled="true"/>

        <security>
          <requestFiltering>
            <requestLimits maxAllowedContentLength="500000000"/>
          </requestFiltering>
        </security>
      </system.webServer>

    Help me to solve the issue.

    Thanks in advance.

    Friday, October 11, 2013 9:14 AM

Answers

  • User260886948 posted

    Hi,

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

    I see that you have increased the size in the configure file, but it still occurs problem, please try to check if you have used the bindingConfiguration as below:

    <endpoint address="" bindingConfiguration="webHttpBinding" binding="webHttpBinding"
    .....>  


    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>


    Best Regards,
    Amy Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 14, 2013 3:35 AM

All replies

  • User220959680 posted

    Request Entity Too Large.

    http://www.codeproject.com/Articles/521725/413-Request-Entity-Too-Large

    WCF by default limits messages to 64KB to avoid DOS attack with large message. By default, it sends byte[] as base64 encoded string and it increases the size of the message (33% increase in size). There for if the uploaded file size is ~larger than 48KB then it raises the above error [copied from the above]

    Below configuration should resolve the issue.

    <bindings>
        <basicHttpBinding>
          <binding maxReceivedMessageSize="10485760"> //Test with this number i..e, 10485760
            <readerQuotas ... />
          </binding>

    Update the thread as progress. Also make sure to update the Service reference on client side.



    Sunday, October 13, 2013 5:17 PM
  • User260886948 posted

    Hi,

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

    I see that you have increased the size in the configure file, but it still occurs problem, please try to check if you have used the bindingConfiguration as below:

    <endpoint address="" bindingConfiguration="webHttpBinding" binding="webHttpBinding"
    .....>  


    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>


    Best Regards,
    Amy Peng

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 14, 2013 3:35 AM