2010-06-09 125 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確保網址的網絡服務都指向到適當的位置。

相關問題