如何将x.509证书添加到Restful WCF服务?

时间:2015-07-10 07:25:41

标签: jquery wcf rest ssl

我是网络服务的新手,所以请耐心等待。我在localhost上托管了一个有效的WCF Restful Service。我想为我的服务添加安全性。 我已经知道我可以将x.509证书添加到服务和jquery客户端。此外,我在this教程之后使用makecert.exe创建了证书。

我已将证书添加到web.config文件中,如教程中所述,但服务不会从jquery客户端请求证书。它只是响应数据。我希望服务只有在从jquery客户端获得证书时才会响应。

我可以看到MMC控制台的可信人员面板下列出的证书。

以下是服务的配置部分

     <system.serviceModel>
    <services>
      <service name="RestDemo.RestDemo" behaviorConfiguration="serviceBehavior">

        <host>
          <baseAddresses>
            <add baseAddress="https://localhost/RestDemo/RestDemo.svc"/>
          </baseAddresses>
        </host>
        <endpoint address="https://localhost/RestDemo/RestDemo.svc" binding="webHttpBinding" contract="RestDemo.IRestDemo" behaviorConfiguration="web">
          <identity>
            <dns value="localhost"/>
          </identity>

        </endpoint>
        <endpoint address="mex"
                  binding="mexHttpsBinding"
                  contract="RestDemo.IRestDemo" />
      </service>
    </services>
    <bindings>

      <webHttpBinding>
        <binding name="web">

          <security mode="Transport">
            <transport clientCredentialType="Certificate"/>

          </security>
        </binding>

      </webHttpBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceBehavior">
          <serviceCredentials>
            <clientCertificate>
              <authentication certificateValidationMode="PeerTrust"/>
            </clientCertificate>
            <serviceCertificate findValue="WCfServer"
              storeLocation="CurrentUser"
              storeName="My"
              x509FindType="FindBySubjectName" />
          </serviceCredentials>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="false" httpsGetEnabled="true"
                          />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">

          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

即使在web.config中添加证书后,我的服务也会将数据返回给客户端。 我在同一台计算机上运行服务和客户端

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

  1. 安装证书
  2. 使用SSL证书配置端口
  3. 配置WCF服务
  4. 有关详细信息,请参阅SSL with Self-hosted WCF Service

相关问题