即使在更新 UploadReadAheadSize

问题描述

我的 WCF 服务公开以接收 XML 文件作为请求的一部分(使用 SOAP UI 进行测试)。为服务端点启用基于证书的身份验证后,IIS 抛出 HTTP/1.1 413 Request Entity Too Large 错误。为解决此问题,在 IIS 配置中将 uploadReadAheadSize 的值更新为“20000000”。该服务能够在配置更改后成功处理请求,当时从客户端收到的文件大小约为 10MB。但后来,观察到同样的问题,发现请求现在包含大小从 15 MB 到 30 MB 不等的 XML 文件。 要解决此问题,请将 uploadReadAheadSize 增加到“90000000”(尝试使用更高的值)。但是这个问题一直存在。 有什么建议可以解决这个问题吗?

当前服务配置:

<bindings>
    <basicHttpsBinding>
        <binding name="BasicHttpBinding.MyService" transferMode="Streamed" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647" messageEncoding="Mtom" receiveTimeout="00:30:00">
            <readerQuotas maxStringContentLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxArrayLength="2147483647" />
            <security mode="Transport">
                <transport clientCredentialType="Certificate" />
            </security>
        </binding>
    </basicHttpsBinding>
</bindings>
<behaviors>
    <serviceBehaviors>
        <behavior name="MyTestProjectIntegrationServiceBehavior">
            <serviceCredentials>
                <serviceCertificate findValue="****************************" storeLocation="LocalMachine" storeName="My" x509FindType="FindByThumbprint" />
            </serviceCredentials>
            <serviceMetadata httpsGetEnabled="true" />
            <CustomBehaviorExtensionElement />
            <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
        <behavior name="MyServiceEndpointBehavior">
            <MyServiceSchemaValidator validateRequest="True" validateReply="False">
                <schemas>
                    <add location="App_Data\MyTestProjectXsd\exchange-model-service.xsd" />
                </schemas>
            </MyServiceSchemaValidator>
        </behavior>
    </endpointBehaviors>
</behaviors>
<system.serviceModel>
    <services>
        <service name="Test.Project.ServiceImplementation.MyService" behaviorConfiguration="MyTestProjectIntegrationServiceBehavior">
            <endpoint binding="basicHttpsBinding" bindingConfiguration="BasicHttpBinding.MyService" contract="ExchangeMyProjectService" behaviorConfiguration="MyServiceEndpointBehavior" bindingNamespace="http://www.test.com/api/end/service" />
        </service>
    </services>
</system.serviceModel>

解决方法

此问题的实际原因是请求大小。一些请求超过 30MB 并导致此错误。为解决此问题,将 IIS 的 maxAllowedContentLength(system.webServer/security/requestFiltering) 更新为 50MB,默认为 30000000(30MB)