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

  • Question

  • Hi, 

    I'm sending SOAP call with attached certificate and I'm getting the following error:The request was aborted: Could not create SSL/TLS secure channel

    Here is my code:
    public static void CallMyWebService()
            {
             try
             { 
                var _url = "https://myurl.com";
                var _action = "https://myurl.com/myAction";
                XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
                HttpWebRequest webRequest = CreateWebRequest(_url, _action);
                InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);
    
                ServicePointManager.Expect100Continue = true;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11;
    
                IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
                
                asyncResult.AsyncWaitHandle.WaitOne();
                
                string soapResult;
                using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
                {
                    using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                    {
                        soapResult = rd.ReadToEnd();
                    }
                    Console.Write(soapResult);
                }
             }
             catch (Exception exc)
             {
                    Console.WriteLine(exc.Message);
              }
         }
          private static HttpWebRequest CreateWebRequest(string url, string action)
            {
                
               
                HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
                webRequest.Headers.Add("SOAPAction", action);
                webRequest.ContentType = "text/xml;charset=\"utf-8\"";
                webRequest.Accept = "text/xml";
                webRequest.Method = "POST";
               
               
    
                string certificatePath2 = "myCertificate.cer";
                X509Certificate certificate2 = new X509Certificate(certificatePath2);
                if (certificate2 == null)
                {
                    certificate2 = X509Certificate.CreateFromCertFile(certificatePath2);
    
                }
                webRequest.ClientCertificates.Add(certificate2);
    
                return webRequest;
            }
    
            private static XmlDocument CreateSoapEnvelope()
            { 
                    XmlDocument soapEnvelopeDocument = new XmlDocument();
               try
                { 
                soapEnvelopeDocument.Load("XMLFile1.xml");
               
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.Message);
                }
                return soapEnvelopeDocument ;
            }
            private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
            {
                try
                { 
                using (Stream stream = webRequest.GetRequestStream())
                {
                    soapEnvelopeXml.Save(stream);
                }
                }
                catch (Exception exc)
                {
                    Console.WriteLine(exc.Message);
                }
            }

    I put both certificates in the bin folder and also in the project folder. Both of the root certificates are installed. 

    Please help



    Tuesday, December 11, 2018 7:46 AM

All replies

  • Hi Barbi Rio_,

    Thank you for posting here.

    For your question, you want to solve the error that could not create SSL/TLS secure channel.

    1. In your code, you set all the TLS/SSL versions, maybe the environment caused the error.

    2. Please provide the specific content information of XMLFile1.xml so that we can test.

    Best regards,

    Jack J Jun.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, December 12, 2018 8:52 AM
    Moderator
  • hi

    1. This is not a problem. I have tried with all SSL/TLS versions and it still doesn't work having same error  with one option and "The underlying connection was closed: An unexpected error occurred on a send." with the others.

    2.It is not possible to provide content information on XMLFile1.xml.  if you want to test use some dummy XML and some URL and action. If my code works with another XML, URL and action than the problem should be in the settings. 

    Thanks

    Sunday, December 16, 2018 2:16 AM
  • Excuse me Jack j Jun  can you explain what happened to the post from  jvigneshcs,?
    Sunday, December 16, 2018 3:51 AM
  • Can I get this message if the web service supplier have not installed my root certificate properly?
    Monday, December 17, 2018 4:49 AM
  • Hi Barbi Rio,

    For your question, this error could be caused if your certificate is not installed correctly.

    Best regards,

    Jack J Jun.


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, December 17, 2018 8:41 AM
    Moderator