wcf - 使用证书身份验证的传输安全

标签 wcf ssl ssl-certificate transport-security

当我访问我的网络服务 localhost/MyService/MyService.svc 时出现以下错误

The SSL settings for the service 'SslRequireCert' does not match those of the IIS 'Ssl, SslNegotiateCert'.

我遵循了 http://msdn.microsoft.com/en-us/library/ms731074.aspx 中指定的 web.config 示例

这是我的 wcf 服务器 web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <appSettings />
  <system.web>
    <identity impersonate="false" />
    <roleManager enabled="true" />
    <authentication mode="Windows" />
    <customErrors mode="Off" />
    <webServices>
      <protocols>
        <add name="HttpGet" />
        <add name="HttpPost" />
      </protocols>
    </webServices>
  </system.web>
  <system.webServer>
    <directoryBrowse enabled="true" />
    <validation validateIntegratedModeConfiguration="false" />
    <security>
      <authorization>
        <remove users="*" roles="" verbs="" />
        <add accessType="Allow" users="*" roles="" />
      </authorization>
    </security>
  </system.webServer>
  <system.serviceModel>
    <services>
      <service name="AspNetSqlProviderService" behaviorConfiguration="MyServiceBehavior">
        <endpoint binding="wsHttpBinding" contract="Interface1" bindingConfiguration="CertificateWithTransportWSHttpBinding" />
        <endpoint binding="wsHttpBinding" contract="Interface2" bindingConfiguration="CertificateWithTransportWSHttpBinding" />
        <endpoint address="mex" binding="wsHttpBinding" bindingConfiguration="CertificateWithTransportWSHttpBinding" name="Metadata_Exchange" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyServiceBehavior">
          <serviceDebug includeExceptionDetailInFaults="True" />
          <serviceMetadata />
          <serviceCredentials>
            <clientCertificate>
              <authentication trustedStoreLocation="LocalMachine"
                               revocationMode="Online"/>
            </clientCertificate>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="CertificateWithTransportWSHttpBinding">
          <security mode="Transport">
            <transport clientCredentialType="Certificate" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
  </system.serviceModel>
</configuration>

我已按如下方式配置 IIS:

  • 使用自签名证书添加 https 绑定(bind)
  • 在 SSL 设置下,选中需要 SSL 并接受客户端证书
  • 自签名证书已添加到本地计算机受信任的根 CA。

我可以浏览并执行 .asmx 服务定义,但是 .svc 给出了上述错误。

最佳答案

尝试注释掉您的 mex 端点。那应该让它工作

关于wcf - 使用证书身份验证的传输安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4082951/

相关文章:

c# - 尝试通过控制同时请求来解决可伸缩性问题

c# - 不显示堆栈跟踪的 wcf 异常

c# - Linux Web 服务器和 .NET 客户端应用程序之间的实时通信

已安装 iOS8 自签名证书但仍不受信任

用于 SSL 证书验证的 PHP 程序

c# - double 类型的问题与区域设置有关

python - 使用 Python 确定 SSL 证书是否是自签名的

ssl - Letsencrypt 不适用于 Android

django - SSL 证书未正确安装在 nginx 网络服务器上(Django 网络应用程序)

https - 在本地使用 LetsEncrypt 生成证书