我创建了一个wcf数据服务,并通过HTTP公开它,需要SSL。 我正在尝试通过证书(相互身份验证)对服务和客户端进行身份验证的设置。 我正在使用开发人员证书。 所以,我将服务器的证书添加到客户的可信人员商店。
但我仍然得到一个例外:“403 - 禁止访问:拒绝访问。”
1-这是我的服务器配置:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingConfig">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
</behaviors>
<services>
<service behaviorConfiguration="" name="PricingDataService">
<endpoint address="https://MyServiceSecure/MyServiceSecure/MyServiceSecure.svc"
binding="webHttpBinding" bindingConfiguration="webHttpBindingConfig"
name="webHttpEndpoint" contract="System.Data.Services.IRequestHandler" />
</service>
</services>
如何让服务器识别客户端的证书? (它也应该是开发者证书)。
2-这是我的客户端配置:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingConfig">
<security mode="Transport">
<transport clientCredentialType="Certificate" />
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="clientCredentialBehavior">
<clientCredentials>
<clientCertificate storeName="TrustedPeople" storeLocation="LocalMachine"
x509FindType="FindBySubjectName" findValue="tempClientcert" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint address="https://MyServiceSecure/MyServiceSecure/MyServiceSecure.svc"
binding="webHttpBinding" bindingConfiguration="webHttpBindingConfig"
contract="System.Data.Services.IRequestHandler" name="" kind=""
endpointConfiguration="" behaviorConfiguration="clientCredentialBehavior">
<identity>
<dns value="MyServiceSecure"/>
</identity>
</endpoint>
</client>
</system.serviceModel>
3-这是我用来调用wcf代码的代码:
> MyServiceContext service = new MyServiceContext (
new Uri("https://MyServiceSecure/MyServiceSecure/MyServiceSecure.svc"));
service.SendingRequest += this.OnSendingRequest_AddCertificate;
//
private void OnSendingRequest_AddCertificate(object sender, SendingRequestEventArgs args)
{
if (null != ClientCertificate)
(args.Request as HttpWebRequest).ClientCertificates.Add(X509Certificate.CreateFromCertFile(@"C:\Localhost.cer"););
}
我是否在服务器上创建证书然后将其安装在客户端上?
答案 0 :(得分:1)
我认为您的证书可能有误,但首先要在IIS中验证网站“SSL设置”下的“客户端证书”是否设置为“接受”或“要求”(以最适合您的方式)。
我认为,为了您的目的,在IIS中为服务器创建自签名证书,然后将此证书导出到.pfx文件并将其安装在受信任的根目录中应该可以正常工作。
如果这对您没有帮助,我会看一下这个问题:Using makecert for Development SSL