Hi all,
I'm having trouble connecting to a Java web service using HttpWebRequest. I
get the error message "The request was aborted: Could not create SSL/TLS
secure channel". The Java service requires a client certificate which they
have provided in .cer format. I can connect ok to their test service which
uses SSL but doesnt require a client certificate with the code below.
I dont have great deal of knowledge about client certificates so anyone got
any ideas why this isnt working?
Thanks
Steve
Details are:
Tried using .net 1.1 and .net 2.0.
Running this code from a Winform application.
I'm connecting using the code below
System.Net.ServicePointManager.CertificatePolicy = new
TrustAllCertificatePolicy();
string url="https://www.websiteurlhere.com";
XmlDocument doc = new XmlDocument();
doc.Load(xml file containing request);
string data=doc.InnerXml;
byte[] buffer=Encoding.UTF8.GetBytes(data);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "POST";
req.ProtocolVersion = HttpVersion.Version10;
req.KeepAlive = false;
req.Headers.Clear();
X509Certificate cert =
X509Certificate.CreateFromCertFile(@"C:\Develop\ce rt_sign.cer");
req.ClientCertificates.Add(cert);
req.ContentLength = buffer.Length;
req.ContentType ="application/x-www-form-urlencoded";
using (Stream reqst = req.GetRequestStream())
{
reqst.Write(buffer, 0, buffer.Length);
reqst.Flush();
}
using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
{
using (Stream rs = response.GetResponseStream())
{
using (StreamReader sr = new StreamReader(rs))
{
string responseDetails = sr.ReadToEnd();
textBox1.Text = responseDetails;
}
}
}