473,473 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with HTTPWebRequest and client certificates

Hi,

I am using HTTPWebRequest to add a client certificate. I am then
using HTTPWebRequest to POST xml to a web service which requires the
attached client certificate to authenticate with their server
certificate. However, I keep getting an error "Unable to connect to
remote server". I know I am able to connect to their server and
retrieve an XML response as we were able to do this using our old
solution (WinHTTP in Visual Basic 6). I have read many articles and
some of them have mentioned ignoring all certificate errors which I am
also doing but with no luck. If anyone has any suggestion it would be
greatly appreciated. The code to add the certificate is below.

webRequest.ClientCertificates.Add(GetCertificate() );

private X509Certificate GetCertificate()
{
///Set store to LocalMachine as this is where the
certificates must be installed
X509Store store = new X509Store(StoreName.My,
StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
//Find certificate based on it's name
X509Certificate2Collection certificates =
store.Certificates.Find(X509FindType.FindBySubject Name, this.sslName,
true);
return certificates[0];
}

The code to ignore certificate errors is below:

ServicePointManager.ServerCertificateValidationCal lback =
new
RemoteCertificateValidationCallback(IgnoreCertific ateErrorHandler);

private bool IgnoreCertificateErrorHandler(object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
//I would log a Information Error so we know if partner
site is iffy on the security side
//But for now, as simple skip error will do
return true;
}

Sending the XML is below. It fails on using (Stream os =
this.webRequest.GetRequestStream())

public string Send(string dataToSend)
{
//Convert our string to a byte array
byte[] bytes = Encoding.ASCII.GetBytes(dataToSend);
this.webRequest.ContentLength = bytes.Length;

//write bytes to server
using (Stream os = this.webRequest.GetRequestStream())
{
os.Write(bytes, 0, bytes.Length);
}

//Get the response
WebResponse webResponse = webRequest.GetResponse();

if (webResponse != null)
{
using (webResponse)
{
using (StreamReader sr = new
StreamReader(webResponse.GetResponseStream(), Encoding.Default))
{
//return the data as string
return sr.ReadToEnd().Trim();
}
}
}
else //we got no response, we return null
{
return null;
}

}
Thanks

Jun 27 '08 #1
0 2365

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

Similar topics

1
by: Curtis Justus | last post by:
Hello, I tried posting this in the aspnet.security group, but it seemed like some posts in this group are closer to what I'm looking for. In any event, I apologize in advance if this isn't the...
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...
1
by: Kevin Landymore | last post by:
I have a vb.net service running under a Domain account. I'm trying to call a web service on our Mainframe (IBM CICS via SSL and Client Certificates) and after a while (1 or 2 days.. thousands of...
2
by: Josef Brunner | last post by:
Hi everybody, my VB.NET (Framework 2.0) client application has to do a HttpWebRequest (for reading web-pages and downloading files) on a web server. The server uses a self-signed certifiacte and...
1
by: WebServiceSecurity | last post by:
The issue involves the following technologies: - 1. .NET 2.0 Framework 2. WSE2.0 (WS-Security) 3. X.509 certificates 4. BEA Weblogic 8.1.5
2
by: steveS | last post by:
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...
0
by: steveS | last post by:
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...
1
by: Joe | last post by:
Hello, I'm currently using a C# class library which is also converted quickly to a console app by adding a MAIN and adjusting the building configuration. I'm using this page as a reference to the...
1
by: am1974po | last post by:
I have 2 applications: One is simple windows application and the other is web service. They are both on the same machine, windows server 2003 - SP2. exactly the same code in both:...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.