Wcf 客户端身份验证方案禁止HTTP请求';匿名';
我正在尝试配置WCF服务器\客户端以使用SSL 我得到以下例外情况: 客户端身份验证方案禁止HTTP请求 “匿名” 我有一个自我托管的WCF服务器。 我已经运行了hhtpcfg 我的客户端和服务器证书都存储在本地计算机上的个人和受信任的人员下 以下是服务器代码:Wcf 客户端身份验证方案禁止HTTP请求';匿名';,wcf,security,https,certificate,Wcf,Security,Https,Certificate,我正在尝试配置WCF服务器\客户端以使用SSL 我得到以下例外情况: 客户端身份验证方案禁止HTTP请求 “匿名” 我有一个自我托管的WCF服务器。 我已经运行了hhtpcfg 我的客户端和服务器证书都存储在本地计算机上的个人和受信任的人员下 以下是服务器代码: binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate; binding.Security.Mode = WebHtt
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
binding.Security.Mode = WebHttpSecurityMode.Transport;
_host.Credentials.ClientCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.PeerOrChainTrust;
_host.Credentials.ClientCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck;
_host.Credentials.ClientCertificate.Authentication.TrustedStoreLocation = StoreLocation.LocalMachine;
_host.Credentials.ServiceCertificate.SetCertificate("cn=ServerSide", StoreLocation.LocalMachine, StoreName.My);
客户端代码:
binding.Security.Mode = WebHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
WebChannelFactory<ITestClientForServer> cf =
new WebChannelFactory<ITestClientForServer>(binding, url2Bind);
cf.Credentials.ClientCertificate.SetCertificate("cn=ClientSide", StoreLocation.LocalMachine, StoreName.My);
ServicePointManager.ServerCertificateValidationCallback
+= RemoteCertificateValidate;
binding.Security.Mode=WebHttpSecurityMode.Transport;
binding.Security.Transport.ClientCredentialType=HttpClientCredentialType.Certificate;
网络频道工厂=
新的WebChannel工厂(绑定,url2Bind);
cf.Credentials.ClientCertificate.SetCertificate(“cn=ClientSide”,StoreLocation.LocalMachine,StoreName.My);
ServicePointManager.ServerCertificateValidationCallback
+=环烷酸盐;
查看web_tracelog.svclog和trace.log
显示服务器无法对客户端证书进行身份验证
我的证书未经授权CA签署
但这就是为什么我把他们添加到信任的人中
我错过了什么?
我遗漏了什么?诀窍是使客户端证书有效 为此,您有两个选择: 1) 使其自签名,然后将其置于“受信任的根证书颁发机构”下 显然,在生产环境中,您希望客户端证书由受信任的CA签名,而不是自签名。 看 2) 使用您创建的另一个证书(我们称之为MyCA)对您的客户端证书进行签名,并将MyCA放在“受信任的根证书颁发机构”中,并将客户端证书放在“受信任的人”中。这样,您的开发环境更接近部署 如何创建和签署证书: 俯视 以下是我使用的一系列命令: 1) makecert-r-pe-ss My-sr LocalMachine-a sha1-sky exchange-n cn=MyCA-sv“MyCAPrivate.pvk”
2) makecert-pe-ss My-sr LocalMachine-a sha1-sky exchange-n cn=SignedClientCertificate-iv“MyCAPrivate.pvk”-ic“MyCAPublic.cer”我收到此错误的原因是因为在我的网络配置中,web服务的URL为
http://localhost/myservicename.svc
在我们的开发服务器上,我们有一个FQDNhttp://dev.myname.com/myservicename.svc.
仔细检查web.configs,确保指向web服务的URL指向正确的位置。第二个命令失败,出现错误:无法加载颁发者证书('MyCAPublic.cer')