none
(400) Bad Request / (413) Request Entity Too Large RRS feed

  • Question

  • Error: When I try to upload a pdf file (>280kb), it throws “The remote server returned an unexpected response: (413) Request Entity Too Large”.

    WCF Service - Web.config 

    <httpRuntime maxRequestLength="2097150" requestLengthDiskThreshold="204800"/>

    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="customBinding" contract="CreateRecord_Service.INewCcmRecord">

    <basicHttpBinding>

            <binding name="customBinding" closeTimeout="00:20:00" openTimeout="00:20:00" sendTimeout="00:20:00" receiveTimeout="00:20:00" maxBufferSize="2147483647"

              maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed" >

              <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />

            </binding>

    </basicHttpBinding>

    
    
    <behaviors>
          <serviceBehaviors>
            <behavior>
              <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false"/>
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <protocolMapping>
          <add binding="basicHttpsBinding" scheme="https"/>
        </protocolMapping>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0"/>
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <security>
          <requestFiltering allowDoubleEscaping="true">
            <requestLimits maxAllowedContentLength="2147483647"/>
            <fileExtensions allowUnlisted="true"/>
            <verbs allowUnlisted="true"/>
          </requestFiltering>
        </security>
        <directoryBrowse enabled="true"/>
      </system.webServer>

    Site/client – Web.config

    <system.web>
        <compilation debug="true" targetFramework="4.0"/>
        <httpRuntime/>
      </system.web>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="BasicHttpBinding_INewCcmRecord"/>    
          </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://localhost:2672/NewCcmRecord.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_INewCcmRecord" contract="NewRecordService.INewCcmRecord"
            name="BasicHttpBinding_INewCcmRecord" />
        </client>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
      </system.serviceModel>

    If I modify the settings in the Web.config of client, it throws “The remote server returned an unexpected response: (400) Bad Request.”

    Modified Web.config

      <system.web>
        <compilation debug="true" targetFramework="4.0"/>
        <httpRuntime maxRequestLength="2097150" requestLengthDiskThreshold="204800"/>
      </system.web>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="BasicHttpBinding_INewCcmRecord" closeTimeout="00:20:00" openTimeout="00:20:00" sendTimeout="00:20:00" receiveTimeout="00:20:00" maxBufferSize="2147483647"
              maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Streamed"/>    
          </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://localhost:2672/NewCcmRecord.svc" binding="basicHttpBinding"
            bindingConfiguration="BasicHttpBinding_INewCcmRecord" contract="NewRecordService.INewCcmRecord"
            name="BasicHttpBinding_INewCcmRecord" />
        </client>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
      </system.serviceModel>

    The application is running on Windows7 with IIS 7. Please let me know if you have any idea about this issue.

    Thanks.


    Wednesday, January 29, 2014 8:52 AM

Answers

  • Hi,

    In your modify web config, you should also add the following:


    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
    maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    Then please try to enable the wcf tracing to find the cause:

    The following configuration taken from MSDN can be applied to enable tracing on your WCF service.

    <configuration> <system.diagnostics> <sources> <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true" > <listeners> <add name="xml"/> </listeners> </source> <source name="System.ServiceModel.MessageLogging"> <listeners> <add name="xml"/> </listeners> </source> <source name="myUserTraceSource" switchValue="Information, ActivityTracing"> <listeners> <add name="xml"/> </listeners> </source> </sources> <sharedListeners> <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="Error.svclog" /> </sharedListeners> </system.diagnostics> </configuration>

    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 30, 2014 2:42 AM
    Moderator
  • Thanks for you reply.

    I think the reference to the service has not been properly updated. What I mean is, my local system has an another service with same name(old one which doesn't has the configuration settings to upload file). So I changed the new service namespace name, project file name and service name.

    Now it works properly.

    Once again thanks.

    Thursday, January 30, 2014 7:11 AM

All replies

  • Hi,

    In your modify web config, you should also add the following:


    <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
    maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
    Then please try to enable the wcf tracing to find the cause:

    The following configuration taken from MSDN can be applied to enable tracing on your WCF service.

    <configuration> <system.diagnostics> <sources> <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true" > <listeners> <add name="xml"/> </listeners> </source> <source name="System.ServiceModel.MessageLogging"> <listeners> <add name="xml"/> </listeners> </source> <source name="myUserTraceSource" switchValue="Information, ActivityTracing"> <listeners> <add name="xml"/> </listeners> </source> </sources> <sharedListeners> <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="Error.svclog" /> </sharedListeners> </system.diagnostics> </configuration>

    Best Regards,
    Amy Peng

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 30, 2014 2:42 AM
    Moderator
  • Thanks for you reply.

    I think the reference to the service has not been properly updated. What I mean is, my local system has an another service with same name(old one which doesn't has the configuration settings to upload file). So I changed the new service namespace name, project file name and service name.

    Now it works properly.

    Once again thanks.

    Thursday, January 30, 2014 7:11 AM