473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

HttpWebRequest and client certificates

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;
}
}
}

Apr 7 '07 #1
2 16295
http://support.microsoft.com/kb/895971 sounds like it describes what you want
to do.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"steveS" wrote:
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;
}
}
}

Apr 9 '07 #2
Hi Peter,
Thanks for the reply and the link but I've already read that article.
I'm struggling to find information on using client certificates for example
when I double click on the client certificate the general tab displays a
message "Windows does not have enough information to verify this
certificate", but I can continue to install the certificate ok. Does this
message mean that the certificate is invalid in someway?

Steve
"Peter Ritchie [C# MVP]" <PR****@newsgroups.nospamwrote in message
news:33**********************************@microsof t.com...
http://support.microsoft.com/kb/895971 sounds like it describes what you
want
to do.

--
Browse http://connect.microsoft.com/VisualStudio/feedback/ and vote.
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#
"steveS" wrote:
>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\c ert_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;
}
}
}

Apr 9 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jonas Oholm (Sweden) | last post by:
Hi I'm using the following ASP-page (taken from http://support.microsoft.com/default.aspx?scid=kb;en-us;216829) to dump client certificates from an SSL connection to a file on the webserver. It...
0
by: paule cyrusse see via .NET 247 | last post by:
How I can implement the use of client certificates? I've alreadygotten a server certificate from verisign and installed it inIIS. I've already enabled SSL and required certificates. I'vealready...
0
by: Russ | last post by:
I have set up a C# web application that runs on my test Web Server (Windows 2003 Server, Web Edition). It in turn calls a web service running on the internal network. Now I want to issue a...
0
by: dinoo | last post by:
Can some body help me out? I am trying to use client certificates in a Webservice. But some how i am not able to make it. I went through the msdn resources but i think some one needs to help me...
1
by: Deepak | last post by:
We retrieve data from a company called XYZ through httpwebrequest. The program is coded using VB.NET They have given a certificate to install. This certificate is included with the request...
0
by: Eric Rosenberger | last post by:
I am developing a web service that uses SSL client certificates for authentication. It works fine with self-generated certificates, but our customer's CA wants specific information about what...
0
by: Ron Fluegge | last post by:
We are developing a Winforms app that retrieves data from our company's SQL Server 2000 database via a webservice. We are considering using something like client certificates so that we have a...
5
by: | last post by:
Hi all, HttpWebRequest, and SoapHttpClientProtocol both expose a ClientCertificates property, which can hold multiple client certificates, but on the service side, it can only receive one client...
2
by: b.fokke | last post by:
I'd like to connect to a webservice using TLS/SSL. I have two separate client certificates: 1. A certificate for digital verification 2. A certificate for encryption. When I use the first one...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.