locked
413 Request Too large RRS feed

  • Question

  • User-1952516322 posted

    Hello,

    I'm facing an issue with pass parameter contain a file from my project to another project ( services ), when I upload a file size 18 KB it's working fine. But when I upload a file or image size 2 MB or more, this error shown up > (413) Request Entity Too Large.

    I'm trying since 2 days to solve this issue, and there is a lot of subjects and options but nothing work for my case

    here is the web.config for "A" project which contain the controllers and views 

    <system.web>
        <compilation debug="true" targetFramework="4.6.1" />
        <httpRuntime targetFramework="4.6.1" maxRequestLength="314572800"  />
        <customErrors mode="On" defaultRedirect="" />
        <httpCookies requireSSL="false" />
      </system.web>
    
    <system.webServer>
        <httpProtocol>
          <customHeaders>
            <remove name="X-Powered-By" />
            <clear />
          </customHeaders>
        </httpProtocol>
      </system.webServer>
    
    <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="FirstService" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
              <readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
            </binding>
            <binding name="SecondService" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
              <readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
            </binding>
          </basicHttpBinding>
    </bindings>
    </system.serviceModel>

    <endpoint address="http://localhost/Services/FirstService.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFirstServiceWrapper"
    contract="FirstServiceWrapperReference.IFirstServiceWrapper"
    name="BasicHttpBinding_IFirstServiceWrapper" />
    <endpoint address="http://localhost/Services/SecondServiceWrapper.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISecondServiceWrapper"
    contract="SecondWrapperReference.ISecondServiceWrapper"
    name="BasicHttpBinding_ISecondServiceWrapper" />

    and here is the "Services" project web.config

    <system.web>
        <httpRuntime maxRequestLength="314572800" />
        <customErrors mode="Off" />
        <compilation debug="true" targetFramework="4.6.1" />
        <authentication mode="Windows" />
      </system.web>
    
    
     <system.webServer>
        <security>
          <requestFiltering>
            <requestLimits maxAllowedContentLength="2200000000" />
          </requestFiltering>
        </security>
        <httpProtocol>
          <customHeaders>
            <remove name="X-Powered-By" />
            <clear />
          </customHeaders>
        </httpProtocol>
      </system.webServer>
    <system.serviceModel>
     <bindings>
      <basicHttpBinding>
     <binding name="BasicHttpBinding_Second1" allowCookies="true"  maxBufferPoolSize="2147483647777" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647">
              <readerQuotas maxDepth="2147483647" maxArrayLength="2147483647" maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
            </binding>
          </basicHttpBinding>
    </bindings>
     <client>
     <endpoint address="http://xxx.xxx.xxx.xx:xxx/Second.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_Second1" contract="SecondReference.xyz"
            name="BasicHttpBinding_Second1" />
     </client>
    

    Controller 

    public ActionResult LoadFile()
            {
                try
                {
                    if (Request.Files.Count > 0)
                    {
                       
                            FileSendClass sender = new FileSendClass()
                            {
                                Id = 1,
                                FileName = Request.Files[0].FileName,
                                FileType = Request["Type"].ToString(),
                                CreatedBy = "ABC",
                                DocId = Convert.ToInt32(Request["docId"]),
                                FileBase64 = extensionHelper.ConvertInputStreamToBytes(Request.Files[0].InputStream),
                                Extension = Path.GetExtension(Request.Files[0].FileName) 
    //Note: Result of FileBase for file 3 MB is >> byte[3047054]
    // I want max size is 10 MB !!
    }; _SecondService.Process(sender); } } catch (Exception ex) { ExceptionManager.HandleException(ex, MethodBase.GetCurrentMethod()); throw ex; } }

    public void UploadFile(FileSendClass file)
            {
                SecondServiceWrapperClient client = new SecondServiceWrapperClient();
                try
                {
                    var response = client.Process(file); /// Here I facing the error. compiler not going to service.. Exception ( 403 Request too large )
                    client.Close();
                    return response;
                }
                catch (Exception ex)
                {
                    client.Abort();
                    ExceptionManager.HandleException(ex, MethodBase.GetCurrentMethod());
                    throw;
                }
                
            }

    I tried a lot of things like, but still I don't know where is the issue?? please if someone know help me.

    Sunday, July 7, 2019 4:21 PM

Answers

  • User-330142929 posted

    Hi,
    It seems that the “A” project is the server side, which hosts the service. The “Services” project is the client side, which consumes the service provided by the “A” project.
    Generally speaking, we are supposed to ensure the server side has applied the configuration at least.
    From the code segments of the “A” project, there is something I don't understand.
    Why the Endpoint section is out of the System.ServiceModel section instead of the Services section that is inside of the System.ServiceModel section? I would like that you could post the complete configuration of the server side.
    It seems that the client consumes the service by using the below server endpoint.

    <endpoint address="http://localhost/Services/SecondServiceWrapper.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISecondServiceWrapper"
    contract="SecondWrapperReference.ISecondServiceWrapper"
    name="BasicHttpBinding_ISecondServiceWrapper" />


    If it indeed, we should apply the configuration on this endpoint. Namely, we use the BindingConfiguration property to apply the configuration.
    Please pay attention to the modification.

    <endpoint address="http://localhost/Services/SecondServiceWrapper.svc"
    binding="basicHttpBinding" bindingConfiguration="SecondService"
    contract="SecondWrapperReference.ISecondServiceWrapper"
    name="BasicHttpBinding_ISecondServiceWrapper" />


    Anyhow, we should at least properly apply the configuration on the server endpoint that is consumed by the client side.
    Here is a related issue, wish it is useful to you.
    https://stackoverflow.com/questions/56755975/error-request-entity-too-large-all-properties-have-top-values/56782870#56782870
    Feel free to let me know if there is anything I can help with.
    Best Regards
    Abraham

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 8, 2019 2:24 AM

All replies

  • User-330142929 posted

    Hi,
    It seems that the “A” project is the server side, which hosts the service. The “Services” project is the client side, which consumes the service provided by the “A” project.
    Generally speaking, we are supposed to ensure the server side has applied the configuration at least.
    From the code segments of the “A” project, there is something I don't understand.
    Why the Endpoint section is out of the System.ServiceModel section instead of the Services section that is inside of the System.ServiceModel section? I would like that you could post the complete configuration of the server side.
    It seems that the client consumes the service by using the below server endpoint.

    <endpoint address="http://localhost/Services/SecondServiceWrapper.svc"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ISecondServiceWrapper"
    contract="SecondWrapperReference.ISecondServiceWrapper"
    name="BasicHttpBinding_ISecondServiceWrapper" />


    If it indeed, we should apply the configuration on this endpoint. Namely, we use the BindingConfiguration property to apply the configuration.
    Please pay attention to the modification.

    <endpoint address="http://localhost/Services/SecondServiceWrapper.svc"
    binding="basicHttpBinding" bindingConfiguration="SecondService"
    contract="SecondWrapperReference.ISecondServiceWrapper"
    name="BasicHttpBinding_ISecondServiceWrapper" />


    Anyhow, we should at least properly apply the configuration on the server endpoint that is consumed by the client side.
    Here is a related issue, wish it is useful to you.
    https://stackoverflow.com/questions/56755975/error-request-entity-too-large-all-properties-have-top-values/56782870#56782870
    Feel free to let me know if there is anything I can help with.
    Best Regards
    Abraham

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 8, 2019 2:24 AM
  • User-1952516322 posted

    Best regards,

    Actually I solved the issue. but as you said,, thanks for your reply.

    Monday, July 8, 2019 2:29 AM