简体   繁体   中英

The request was aborted: Could not create SSL/TLS secure channel Exception

Let me explain my situation.

I created a self-signed certificate and installed it in the Trusted Root Certification Authorities section in MMC.

I then created two certificates using the self-signed certificate:

  1. A certificate with subject name "localhost"
  2. A certificate with subject name "test.com"

I then installed both certificates into the Personal certificates section in MMC.

I then deployed a web service as HTTPS (SSL with accept client certificates) in IIS. The certificate used to deploy the web service is the one with subject name "localhost".

Now, I have a client who wants to connect to the web service. I successfully added a web reference to the service. This is the code:

            ClientServices web_service = new ClientServices();
            X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
            store.Open(OpenFlags.ReadOnly);
            X509Certificate2Collection col = store.Certificates.Find(X509FindType.FindBySubjectName, "test.com", true);

            if (col.Count == 1)
            {
                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls;
                web_service.ClientCertificates.Add(col[0]);

                try
                {
                    string hello = web_service.HelloWorld();
                    int add = web_service.add(4, 31);
                    int sub = web_service.subtract(30, 10);

                    Console.WriteLine(hello);
                    Console.WriteLine(add);
                    Console.WriteLine(sub);
                }
                catch (WebException e)
                {
                    Console.WriteLine(e.Message.ToString());
                }
            }

            else
            {
                Console.WriteLine("The certificate was not found!");
            }
            Console.ReadKey();

As you can see, I am sending the "test.com" certificate along with the web service request. Unfortunately, I am getting this exception:

The request was aborted: Could not create SSL/TLS secure channel

How can I solve this problem? I have already wasted 3 hours on this issue. Please help me.

private void Somewhere() {
    ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AllwaysGoodCertificate);
}

private static bool AllwaysGoodCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors) {
   return true;
}

Source: The request was aborted: Could not create SSL/TLS secure channel

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM