(413) Request Entity Too Large | uploadReadAheadSize

前端 未结 13 1441
迷失自我
迷失自我 2020-11-22 07:33

I\'ve written a WCF service with .NET 4.0, which is hosted on my Windows 7 x64 Ultimate system with IIS 7.5. One of the service methods has an \'object\' as arg

相关标签:
13条回答
  • 2020-11-22 08:17

    for issue the remote server returned an unexpected response: (413) Request Entity Too Large on WCF with Resful

    please see my explain configuration

    </client>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="false" aspNetCompatibilityEnabled="true"/>
    
    <bindings>
    
       <!-- this for restfull service -->
      <webHttpBinding>
        <binding name="RestfullwebHttpBinding"
          maxBufferPoolSize="2147483647"
          maxReceivedMessageSize="2147483647"
          maxBufferSize="2147483647" transferMode="Streamed">
    
          <readerQuotas 
            maxDepth="2147483647" 
            maxStringContentLength="2147483647"
            maxArrayLength="2147483647" 
            maxBytesPerRead="2147483647" /> 
    
        </binding>
      </webHttpBinding>
      <!-- end -->
    
       <!-- this for Soap v.2 -->
      <wsHttpBinding>
        <binding name="wsBinding1" maxReceivedMessageSize="2147483647" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
          <!--UsernameToken over Transport Security-->
          <security mode="TransportWithMessageCredential">
            <message clientCredentialType="UserName" establishSecurityContext="true"/>
          </security>
        </binding>
      </wsHttpBinding>
       <!-- this for restfull service -->
    
       <!-- this for Soap v.1 -->
      <basicHttpBinding>
        <binding name="basicBinding1" maxReceivedMessageSize="2147483647" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false" transferMode="Streamed">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
          <security mode="None"/>
        </binding>
      </basicHttpBinding>
    </bindings> 
    <!-- end -->
    
    <services>
      <clear/>
    
      <service name="ING.IWCFService.CitisecHashTransfer"  >
        <endpoint address="http://localhost:8099/CitisecHashTransfer.svc"
                      behaviorConfiguration="RestfullEndpointBehavior"
                      binding="webHttpBinding"
                      bindingConfiguration="RestfullwebHttpBinding"
                      name="ICitisecHashTransferBasicHttpBinding"
                      contract="ING.IWCFService.ICitisecHashTransfer" />
      </service>
    
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
    
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="ING.IWCFService.IWCFServiceValidator, ING.IWCFService"/>
          </serviceCredentials>
          <serviceSecurityAudit auditLogLocation="Application" serviceAuthorizationAuditLevel="SuccessOrFailure" messageAuthenticationAuditLevel="SuccessOrFailure"/>
          <serviceThrottling maxConcurrentCalls="1000" maxConcurrentSessions="100" maxConcurrentInstances="1000"/>
    
        </behavior>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
          <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="EndpointBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
        </behavior> 
        <behavior name="RestfullEndpointBehavior">
          <dataContractSerializer maxItemsInObjectGraph="2147483647"  />
          <webHttp/>
        </behavior> 
      </endpointBehaviors>
    </behaviors>
    

    0 讨论(0)
  • 2020-11-22 08:19

    I had the same problem and setting the uploadReadAheadSize solved it:

    http://www.iis.net/configreference/system.webserver/serverruntime

    "The value must be between 0 and 2147483647."

    It is easily set it in the applicationHost.config-fle if you don't want to do a cmd-thing.

    Its located in WindowsFOLDER\System32\inetsrv\config (2008 server).

    You must open it with notepad. Do a Backup of the file first.

    According to the comments in config the recommended way to unlock sections is by using a location tag:

    <location path="Default Web Site" overrideMode="Allow">
        <system.webServer>
            <asp />
        </system.webServer>
    </location>"
    

    So you can write in the bottom (since it doesn't exist before). I write maxvalue here - write your own value if you want.

    <location path="THENAMEOFTHESITEYOUHAVE" overrideMode="Allow">
        <system.webServer>
            <asp />
            <serverRuntime uploadReadAheadSize="2147483647" />
        </system.webServer>
    </location>
    

    If you put it last before </configuration> for example, you know where you have it.

    Hope that solves your problems. It was an SSL overhead issue for me, where too much post freezed the application, raising a (413) Request Entity Too Large error.

    0 讨论(0)
  • 2020-11-22 08:19

    If you're running into this issue despite trying all of the solutions in this thread, and you're connecting to the service via SSL (e.g. https), this might help:

    http://forums.newatlanta.com/messages.cfm?threadid=554611A2-E03F-43DB-92F996F4B6222BC0&#top

    To summarize (in case the link dies in the future), if your requests are large enough the certificate negotiation between the client and the service will fail randomly. To keep this from happening, you'll need to enable a certain setting on your SSL bindings. From your IIS server, here are the steps you'll need to take:

    1. Via cmd or powershell, run netsh http show sslcert. This will give you your current configuration. You'll want to save this somehow so you can reference it again later.
    2. You should notice that "Negotiate Client Certificate" is disabled. This is the problem setting; the following steps will demonstrate how to enable it.
    3. Unfortunately there is no way to change existing bindings; you'll have to delete it and re-add it. Run netsh http delete sslcert <ipaddress>:<port> where <ipaddress>:<port> is the IP:port shown in the configuration you saved earlier.
    4. Now you can re-add the binding. You can view the valid parameters for netsh http add sslcert here (MSDN) but in most cases your command will look like this:

    netsh http add sslcert ipport=<ipaddress>:<port> appid=<application ID from saved config including the {}> certhash=<certificate hash from saved config> certstorename=<certificate store name from saved config> clientcertnegotiation=enable

    If you have multiple SSL bindings, you'll repeat the process for each of them. Hopefully this helps save someone else the hours and hours of headache this issue caused me.

    EDIT: In my experience, you can't actually run the netsh http add sslcert command from the command line directly. You'll need to enter the netsh prompt first by typing netsh and then issue your command like http add sslcert ipport=... in order for it to work.

    0 讨论(0)
  • 2020-11-22 08:20

    In my case, I was getting this error message because I was changed the service's namespace and services tag was pointed to the older namespace. I refreshed the namespace and the error disapear:

    <services>
      <service name="My.Namespace.ServiceName"> <!-- Updated name -->
        <endpoint address="" 
                  binding="wsHttpBinding" 
                  bindingConfiguration="MyBindingConfiguratioName" 
                  contract="My.Namespace.Interface" <!-- Updated contract -->
        />
      </service>
    </services>
    
    0 讨论(0)
  • 2020-11-22 08:23

    Got a similar error on IIS Express with Visual Studio 2017.

    HTTP Error 413.0 - Request Entity Too Large

    The page was not displayed because the request entity is too large.

    Most likely causes:

    • The Web server is refusing to service the request because the request entity is too large.

    • The Web server cannot service the request because it is trying to negotiate a client certificate but the request entity is too large.

    • The request URL or the physical mapping to the URL (i.e., the physical file system path to the URL's content) is too long.

    Things you can try:

    • Verify that the request is valid.

    • If using client certificates, try:

      • Increasing system.webServer/serverRuntime@uploadReadAheadSize

      • Configure your SSL endpoint to negotiate client certificates as part of the initial SSL handshake. (netsh http add sslcert ... clientcertnegotiation=enable) .vs\config\applicationhost.config

    Solve this by editing \.vs\config\applicationhost.config. Switch serverRuntime from Deny to Allow like this:

    <section name="serverRuntime" overrideModeDefault="Allow" />
    

    If this value is not edited, you will get an error like this when setting uploadReadAheadSize:

    HTTP Error 500.19 - Internal Server Error

    The requested page cannot be accessed because the related configuration data for the page is invalid.

    This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".

    Then edit Web.config with the following values:

    <system.webServer>
      <serverRuntime uploadReadAheadSize="10485760" />
    ...
    
    0 讨论(0)
  • 2020-11-22 08:24

    For me, setting the uploadReadAheadSize to int.MaxValue also fixed the problem, after also increasing the limits on the WCF binding.

    It seems that, when using SSL, the entire request entity body is preloaded, for which this metabase property is used.

    For more info, see:

    The page was not displayed because the request entity is too large. iis7

    0 讨论(0)
提交回复
热议问题