2010-06-09 111 views
15

我想配置一个WCF服务器\客户端SSL工作HTTP请求与客户端身份验证方案“无名氏”禁止

我得到以下异常:

The HTTP request was forbidden with client authentication scheme 'Anonymous'

我有一个自我托管的WCF服务器。 我已经运行hhtpcfg 我的两个客户端和服务器证书存储的个人和信任的人在本地计算机上的

这里是服务器代码:

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; 

查看web_tracelog.svclog和trace.log 显示服务器无法验证客户端证书 我的证书未由授权人签名但这就是我将它们添加到可信人员的原因....

我在想什么? 我错过了什么?

回答

7

诀窍是让客户端证书有效,

要做到这一点,你有两个选择:

1)使其自签名,然后把它放在“受信任的根证书颁发机构”下。

显然在生产中,您希望您的客户端证书由受信任的CA签署,而不是自签名。 看到http://msdn.microsoft.com/en-us/library/ms733813.aspx

2)登录您的客户端证书由您创建的其他证书(姑且称之为MyCA),并把MyCA在“受信任的根证书颁发机构”,并在“受信任的人”的客户端证书。这样您的开发环境就更接近部署。

如何创建和签署的证书: 下看http://msdn.microsoft.com/en-us/library/bfsktky3.aspx

这是该系列我用命令:

1)makecert -r -pe -ss我-sr LOCALMACHINE -a SHA1 - 天空交换-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“

+1

第二个命令失败,错误:无法加载颁发者证书('MyCAPublic.cer') – TDaver 2011-06-20 14:45:40

1

reas在我收到此错误是因为在我的webconfig,Web服务具有http://localhost/myservicename.svc URL和我们的开发服务器上,我们有一个FQDN http://dev.myname.com/myservicename.svc.

仔细检查您的web.configs确保网址的网络服务都指向到适当的位置。

相关问题