2010-05-08 60 views
25

我有一個使用自簽名證書在IIS 7中運行的WCF Web服務(這是驗證這是我想要的路線的概念證明)。它需要使用SSL。是否可以強制WCF測試客戶端接受自簽名證書?

是否可以使用WCF測試客戶端調試此服務而不需要非自簽名證書?

當我嘗試我得到這個錯誤:

Error: Cannot obtain Metadata from https:///Service1.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: https:///Service1.svc Metadata contains a reference that cannot be resolved: 'https:///Service1.svc'. Could not establish trust relationship for the SSL/TLS secure channel with authority ''. The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. The remote certificate is invalid according to the validation procedure.HTTP GET Error URI: https:///Service1.svc There was an error downloading 'https:///Service1.svc'. The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. The remote certificate is invalid according to the validation procedure.

編輯:這個問題是特別關於使用WCF測試客戶端測試使用自簽名證書通過SSL已經獲得的網絡服務。服務器已經設置爲接受任何提供的證書,這是WCF測試客戶端,我沒有看到這樣做的方法。

回答

-4

您可以提供自己的方法來驗證證書。

試試這個:

ServicePointManager.ServerCertificateValidationCallback += 
      new System.Net.Security.RemoteCertificateValidationCallback(EasyCertCheck); 

回叫:

bool EasyCertCheck(object sender, X509Certificate cert, 
     X509Chain chain, System.Net.Security.SslPolicyErrors error) 
{ 
    return true; 
} 
+0

我沒有看到任何方式將此代碼添加到WCF測試客戶端(我不控制的代碼)。我已經將此調用添加到我自己的代碼(服務器端)。 – 2010-05-10 15:06:56

+0

當然,如果您試圖強制任何其他C#WCF客戶端接受自簽名安全證書,這是正確的方法。 – stephen 2014-07-25 21:31:17

3

,你應該能夠做到這一點,如果你WCFStorm Lite Edition更換WCF測試客戶端。它是免費的,比MS的測試客戶端更加靈活...例如,如果您正在進行用戶名認證,它將允許您指定用戶名&密碼。

+4

如果你和我一樣,也不喜歡下載你從未聽說過的軟件,這裏是Visual Studio雜誌對WFCStorm的評論。 http://visualstudiomagazine.com/articles/2012/10/29/free-tool-wcfstorm.aspx – 2013-08-12 01:58:55

3

this question的回答對我有幫助。確保使用精確機器名稱作爲證書期望。例如machine/service.svc可能無法正常工作,而machine.domain/service.svc - 工作。

+0

礦是另一種方式(如machine.domain失敗,而機器只是工作)。謝謝! – johnofcross 2013-08-23 17:50:04

12

您可以在開發區域創建一個非自簽名證書,然後在IIS中使用此證書來應用SSL。步驟如下:

  1. 創建自簽名證書

    makecert -r -pe -n "CN=My Root Authority" -a sha1 -sky signature 
        -ss CA -sr CurrentUser 
        -cy authority 
        -sv CA.pvk CA.cer
  2. 創建SSL非自簽名證書,簽署此根證書,然後創建從

    PFX文件
    makecert -pe -n "CN=servername" -a sha1 -sky exchange 
        -eku 1.3.6.1.5.5.7.3.1 -ic CA.cer -iv CA.pvk 
        -sp "Microsoft RSA SChannel Cryptographic Provider" 
        -sy 12 -sv server.pvk server.cer 
    
    pvk2pfx -pvk server.pvk -spc server.cer -pfx server.pfx

現在您只需將server.pfx導入IIS並設置網絡ite綁定使用此證書,並通過這樣安裝 Local Computer \ Trusted Root Certification Authorities存儲在服務器和客戶端通過這樣做WCF客戶端將通過HTTPS的服務工作沒有任何問題。

+0

+1詳細信息 – bugnuker 2012-05-22 14:56:51

+3

你美!還有一個竅門是,你可能會得到一個無效的密碼錯誤,你可以通過在最後一行的命令行上傳遞密碼來解決:pvk2pfx -pvk server.pvk -pi「yourpw」-spc server.cer -pfx server.pfx -po 「yourpw」 – 2012-05-31 04:30:11

+0

在服務器上添加pfx時,我收到了有關密碼錯誤的錯誤消息,但我只是跳過了輸入密碼的操作,但似乎都沒有問題。 – 2013-11-27 19:42:52

1

要回答你的問題...這裏是你如何迫使你的WCF測試客戶端接受自簽名證書...

 using (ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client()) 
     { 
      System.Net.Security.RemoteCertificateValidationCallback callBack = (sender, certificate, chain, sslPolicyErrors) => true; 
      ServicePointManager.ServerCertificateValidationCallback += callBack; 

      Console.WriteLine(proxy.GetData(35)); 

      ServicePointManager.ServerCertificateValidationCallback -= callBack; 
     } 
+0

我認爲他的意思是_WCFTestClient.exe_。無論如何,你的答案幫助我用我的WCF測試客戶端** Project **。 – 2015-05-21 20:33:14

相關問題