WCF SSL证书身份验证无法识别配置设置



我正在尝试在WCF/.NET 4.0版IIS 7.5版中使用SSL证书身份验证,但是,当我启用oneToOneMappings身份验证时,系统无法识别maxReceivedMessageSize,当我注释掉oneToOneMaps身份验证部分时,IIS会识别maxReceivetMessageSize变量。

关于如何让这个WCF服务使用我在启用SSL证书身份验证时设置的maxReceivedMessageSize值,有什么想法吗?

服务模型部分:

<system.serviceModel>
    <services>
      <service behaviorConfiguration="AServiceBehavior" name="<IContract>">
        <endpoint address=""  binding="basicHttpBinding" bindingConfiguration="MutualSslBinding" contract="<IContract>"  name="AnEndpoint" />
        <host><baseAddresses><add baseAddress="https://asite.com/service" /></baseAddresses></host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="AServiceBehavior">
          <serviceCredentials>
          </serviceCredentials>
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true" />
          <serviceSecurityAudit auditLogLocation="Security" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  <bindings>
      <basicHttpBinding>
        <binding name="MutualSslBinding" axReceivedMessageSize="2147483647">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
                    maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="Transport"> <transport clientCredentialType="Certificate" /></security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true">
    </serviceHostingEnvironment>  
  </system.serviceModel>

证书安全部分:

<system.webServer>
    <security>
      <access sslFlags="Ssl, SslNegotiateCert, SslRequireCert" />
      <authentication>
        <anonymousAuthentication enabled="true" />
        <basicAuthentication enabled="false" />
        <clientCertificateMappingAuthentication enabled="false" />
        <digestAuthentication enabled="false" />
        <windowsAuthentication enabled="false" />
        <iisClientCertificateMappingAuthentication enabled="true" oneToOneCertificateMappingsEnabled="true" manyToOneCertificateMappingsEnabled="true">
          <oneToOneMappings>
                        <clear />
                        <add userName="<LocalUser>" password="<EncryptedPassword>" certificate="<Authentication certificate text>" />
          </oneToOneMappings>
        </iisClientCertificateMappingAuthentication>
      </authentication>
    </security>
    <modules runAllManagedModulesForAllRequests="true" />
    <directoryBrowse enabled="false" />
  </system.webServer>

在这种特定情况下,问题与WCF配置无关,而是与IIS中的uploadReadAheadSize设置有关。

TLS开销

当您使用SSL证书身份验证时,在身份验证过程中,请求的开销可能会增加到49Kb以上。

返回错误413实体过大

使用uploadReadAheadSize控制IIS允许的请求大小

首先验证IIS请求筛选。

要执行此操作,请打开IIS管理器。选择您的应用程序。在功能视图中,您将看到"请求筛选"。打开此功能,在右侧面板上会发现"编辑功能设置"允许的最大内容长度"是可选的U-Int属性。它指定请求中内容的最大长度,以字节为单位。默认值为30000000,约为28.6MB。接下来,我们可以在IIS中设置uploadReadAheadSize。

要导航到此设置,请使用以下步骤:

启动"Internet Information Services(IIS)Manager"

  • 展开"服务器"字段
  • 展开网站
  • 选择您的应用程序所在的网站
  • 在"功能"部分,双击"配置编辑器"
  • 在"Section"下选择:system.webServer>serverRuntime

默认设置值为49Kb。

董万军在MSDN 上提供的回复

服务器运行时设置

最新更新