webHttpBinding安全性不包含消息节点?

Kyl*_*yle 4 wcf web-config client-certificates

我正在尝试将客户端证书应用于WCF REST服务.我找到了一些有关应用具有以下内容的客户端证书的详细信息:

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpEndpointBinding">
      <security>
        <message clientCredentialType="Certificate" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)

在这种情况下似乎没有问题.然而,我使用webHttpBinding,我得到一个错误,指出messagesecurity节点是一个无效的子节点.

我是不是要不正确地设置客户端证书?有人能够指出我正确的方向.

Mik*_*win 6

wsHttpBinding配置中的消息节点是关于配置SOAP消息安全头的,这就是为什么它对webHttpBinding无效,而webHttpBinding不是基于SOAP(它是REST)

REST服务的适当安全性很可能是传输级别 - 即HTTPS.

如果要使用消息级别安全性,则需要切换到SOAP,但消息级别相当专业,在大多数情况下不是必需的.

如果需要使用webHttpBinding证书(这意味着使用相互SSL),则需要将securityMode设置为Transport,将clientCredentialType属性设置为Certificate.在配置中,它在服务器端看起来像这样

  <webHttpBinding>
    <binding name="ClientCertServerSide">
      <security mode="Transport" >
       <transport clientCredentialType="Certificate"/>
      </security> 
    </binding>
  </webHttpBinding> 
Run Code Online (Sandbox Code Playgroud)

在客户端,您可以在代码中指定证书(使用HttpWebRequest.ClientCertificates属性)或在config中.在配置中它看起来像

    <endpointBehaviors>
        <behavior name="ClientCertClientSide">
            <clientCredentials>
                <clientCertificate findValue="put the cert name here" storeLocation="put the store here" />
            </clientCredentials>
        </behavior>
    </endpointBehaviors>
Run Code Online (Sandbox Code Playgroud)