HttpWebRequest请求已中止:无法创建SSL / TLS安全通道

时间:2015-09-17 10:45:47

标签: c# asp.net web-services ssl-certificate

我已经开发了asp.net web应用程序并在本地使用iisexpress运行它。 我想调用需要两个方法的webservice。

我有本地机器安装的客户端证书,完全控制Network_service,使用证书mmc登录用户。

使用以下代码调用服务

 ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
     | SecurityProtocolType.Tls11
     | SecurityProtocolType.Tls12
     | SecurityProtocolType.Ssl3;

        HttpWebRequest request = WebRequest.Create(new Uri(_endPoint)) as HttpWebRequest;

        // Set type to POST
        request.Method = "GET";
        request.ContentType = "application/xml";
        _endPoint = _endPoint + "?callerFID='" + _callerFID + "'&callerID='" + _callerID;
        X509Certificate2 cert = new X509Certificate2("C:\\test.p12", "TEST");
        System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(Object obj, X509Certificate X509certificate, X509Chain chain, System.Net.Security.SslPolicyErrors errors)
        {
            return true;
        };
        request.ClientCertificates.Add(cert);

        request.PreAuthenticate = true;
        try
        {
            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());
                string result = reader.ReadToEnd();
                reader.Close();
            }
            return new IMSUserManagementService.UserManagerV2Client(_endPoint);
        }
        catch (Exception)
        {

            throw;
        }

但是获得异常:请求已中止:无法创建SSL / TLS安全通道

请帮我解决问题

0 个答案:

没有答案