代码之家  ›  专栏  ›  技术社区  ›  hinewwiner

WCF自托管REST服务器(HTTPS)不断请求客户端身份验证

  •  1
  • hinewwiner  · 技术社区  · 7 年前

    我创建了一个自托管的WCF REST服务器(不带IIS)。当我启用SSL支持时,当我在chrome中测试站点时,会一直要求我提供客户端认证。

    下面是我的app.config,我认为它禁用了客户端身份验证。我这里有什么东西不见了吗?

    照片: Chrome asking for client certificate

    app.config代码:

     <system.serviceModel>
    <services>
      <service behaviorConfiguration="ADConnectorLibrary.Service1Behavior" name="ADConnectorLibrary.ADConnectorLibrary">
        <endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpTransportSecurity" behaviorConfiguration="web" contract="ADConnectorLibrary.IADConnectorLibrary" >
        </endpoint>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
        <host>
          <baseAddresses>
            <add baseAddress="https://ADDRESS:8888/ADConnectorLibrary/"/>
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ADConnectorLibrary.Service1Behavior">
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
          **<serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="None" />
            </clientCertificate>
          </serviceCredentials>**
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
        <binding name="webHttpTransportSecurity">
          <security mode="Transport">
            **<transport clientCredentialType="None" />**
          </security>
        </binding>
      </webHttpBinding>
    </bindings>
    

    2 回复  |  直到 7 年前
        1
  •  0
  •   Abraham Qian    7 年前

    您唯一需要做的就是在IIS中托管服务时禁用SSL设置。 enter image description here enter image description here

    在我这方面,我创建了一个控制台应用程序来承载服务,并使用以下命令将sslcert绑定到指定的端口。当客户端通过浏览器调用它时,它不会弹出对话框并提示我选择客户端证书。

    netsh http添加sslcert ipport=0.0.0.0:8000 证书哈希=000000000003ED9CD0C315BB6DC1C08DA5E6 appid=00112233-4455-6677-8899-aabbccddeeff_

    也许我们不需要打开或禁用支持客户端证书。

    clientCertNegotiation=禁用

    这是官方文件,希望对你有用。
    https://docs.microsoft.com/en-us/windows/desktop/http/add-sslcert
    https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-configure-a-port-with-an-ssl-certificate

    如果有什么我能帮忙的,请随时告诉我。

        2
  •  0
  •   Popo    7 年前

    因为您使用的是TransportSecurity,所以我认为您需要为您的服务分配一个证书,否则它将无法通过HTTPS通过SSL加密消息。

    同样,当客户端试图通过浏览器中的HTTPS访问服务时,客户端必须信任该证书,或者将获得其中一个响应,并且来自代码的调用将失败。

    enter image description here

    您可能需要使用netsh,因为您不使用IIS。您可能需要重新拔插netsh以满足您的需要。

    这样做是为了将证书注册到端口并映射到应用程序guid:这是一个纯粹的组合示例: netsh http add sslcert ipport=127.0.0.1:8000 certhash=c20ed305ea705cc4e36b317af6ce35dc03cfb83d appid={c9670020-5288-47ea-70b3-5a13da258012} clientcertnegotiation=enable

    您可能不需要这样做,因为您没有申请证书:

     **<serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="None" />
            </clientCertificate>
          </serviceCredentials>**
    
    推荐文章