【发布时间】:2015-07-10 07:25:40
【问题描述】:
我是 Web 服务的新手,所以请多多包涵。我在 localhost 上托管了一个可用的 WCF Restful 服务。我想为我的服务增加安全性。 我知道我可以将 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 中添加证书后,我的服务也会向客户端返回数据。 我在同一台机器上同时运行服务和客户端。
我在这里做错了什么?
【问题讨论】: