对wcf服务发出https请求:根据验证程序,远程证书无效

sur*_*ash 5 c# asp.net wcf iis-7

我在本地计算机上通过http/https托管服务.当我通过http使用服务时,它工作得很好.当我在ajax上发出https请求时,它也有效.但是,当我尝试从客户端应用程序后面的代码中使用它时,它不起作用.它显示如下错误消息:

"The remote certificate is invalid according to the validation procedure"
Run Code Online (Sandbox Code Playgroud)

有人可以帮帮我吗?

Ras*_*ash 7

这是因为您在本地IIS上使用的证书是虚拟证书.可能,你不会实时得到它.有几种黑客可以使它在本地工作.

注意:永远不要在生产中这样做......

在调用任何服务方法之前,添加以下代码段(事件处理程序).

 ServicePointManager.ServerCertificateValidationCallback +=
        EasyCertCheck;

 bool EasyCertCheck(object sender, X509Certificate cert,
   X509Chain chain, System.Net.Security.SslPolicyErrors error)
    {
        return true;
    }
Run Code Online (Sandbox Code Playgroud)