troubleshooting Question

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

Avatar of mathew_s
mathew_s asked on
C#SSL / HTTPSWCF
2 Comments1 Solution2030 ViewsLast Modified:
I have created a windows service and installed a certificate on my local machine. I am sending an XML query to the remote server and expecting a response back. I am getting an error: The request was aborted: Could not create SSL/TLS secure channel.

The error occurs on the following line:
            using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))

Note  that I have replaced text that is sensitive with blah.
Any ideas?

        public static void CallWebService()
        {
            var _url = "https://blah";
            var _action = "https://blah";


            XmlDocument soapEnvelopeXml = CreateSoapEnvelope();
            HttpWebRequest webRequest = CreateWebRequest(_url, _action);
            InsertSoapEnvelopeIntoWebRequest(soapEnvelopeXml, webRequest);



            // begin async call to web request.
            IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);


            // suspend this thread until call is complete. 
            asyncResult.AsyncWaitHandle.WaitOne();


            // get the response from the completed web request.
            string soapResult;

            using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult)) //error occurs here!!
            {
                using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                {
                    soapResult = rd.ReadToEnd();
                }
                Console.Write(soapResult);
                Console.Read();
            }

        }


        private static HttpWebRequest CreateWebRequest(string url, string action)
        {
            HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
            webRequest.Headers.Add("SOAPAction", action);
            webRequest.ContentType = "text/xml";
            //webRequest.ContentLength = ddd;
            webRequest.Accept = "text/xml";
            webRequest.Method = "POST";

            //create the proxy
            ICredentials credentials = new NetworkCredential("Blah", "");
            IWebProxy webProxy = new WebProxy("http://blah.com:9090", true);
            webProxy.Credentials = credentials;
            webRequest.Proxy = webProxy;

            return webRequest;
        }

        private static XmlDocument CreateSoapEnvelope()
        {
            XmlDocument soapEnvelop = new XmlDocument();
            soapEnvelop.LoadXml(@"<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/1999/XMLSchema""><SOAP-ENV:Body><QueryRequest><Blah><All/></Blah></QueryRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>");
            return soapEnvelop;
        }

        private static void InsertSoapEnvelopeIntoWebRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
        {
            using (Stream stream = webRequest.GetRequestStream())
            {
                soapEnvelopeXml.Save(stream);
            }
        }
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros