mathew_s
asked on
The request was aborted: Could not create SSL/TLS secure channel
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( asyncResul t))
Note that I have replaced text that is sensitive with blah.
Any ideas?
The error occurs on the following line:
using (WebResponse webResponse = webRequest.EndGetResponse(
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);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
private static HttpWebRequest CreateWebRequest(string url, string action)
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest
webRequest.Headers.Add("SO
webRequest.ContentType = "text/xml";
//webRequest.ContentLength
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;
X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine
store.Open(OpenFlags.ReadO
X509Certificate2Collection
webRequest.ClientCertifica
store.Close();
return webRequest;
}