为什么在作为Windows服务托管的休息服务上添加基于证书的身份验证,无法启动服务?

时间:2016-11-10 12:55:07

标签: ssl windows-services wcf-ria-services wcf-binding wcf-security

我创建了WCF REST服务并作为Windows服务托管。我从以下帖子中获取了参考文献。

http://www.codeproject.com/Tips/1009004/WCF-RESTful-on-Windows-Service-Host

现在我正在尝试添加基于证书的身份验证。

我在配置文件中添加了以下部分。 注意:我按照以下msdn链接添加了验证 https://msdn.microsoft.com/en-us/library/ff648360.aspx

<bindings>
  <wsHttpBinding>
    <binding name="wsHttpEndpointBinding">
      <security>
        <message clientCredentialType="Certificate" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

 <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
          <serviceCredentials>
            <serviceCertificate findValue="CN=tempCertServer" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>

我安装了Windows服务并尝试启动它。它会引发错误。

enter image description here

我删除了以下部分

<serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
      <serviceCredentials>
        <serviceCertificate findValue="CN=tempCertServer" />
      </serviceCredentials>
    </behavior>
  </serviceBehaviors>

并且错误消失。显然认证工作。

可能是什么原因? 我正在为托管为Windows服务的休息服务正确添加基于证书的身份验证吗?

1 个答案:

答案 0 :(得分:1)

I got the solution.I made following change 

<serviceDebug includeExceptionDetailInFaults="true" />
        I saw the exception in event view logs. service was not able to find certificate,
hence not started.Again created certificate and it works. 
For creating certificate follow following link closely.

https://msdn.microsoft.com/en-us/library/ff648498.aspx