2010-05-08 82 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

相关问题