1

Im using a webservice in my program.

this is the web service : "https://X.Y.Z.W/ib/ws/openbill.asmx?wsdl"

It works as local. when I write this on Internet Explorer, I can see the proper page after selecting "Continue to this website (not recommended)" in this attachment : enter image description here

but when I want to access to this, in my c# code, I get this exception :

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

So how can I access this in my c# program?

Elahe
  • 1,379
  • 2
  • 18
  • 34
  • Off-topic but when you see this page you should not simply click on continue, specially when you are working with a billing service. – Reza Aghaei Oct 17 '15 at 15:02
  • @RezaAghaei I just want to access this page in my program. I trust it – Elahe Oct 17 '15 at 15:14
  • - Is time of your OS correct? - Are you sure the certificate of that server is OK? - Do you have a certificate to install in your Trusted Root CA? – Reza Aghaei Oct 17 '15 at 15:16
  • Why do you use the IP address? Isn't there is a host name such as something.com who matches the common name of the certificate? – Lex Li Oct 17 '15 at 17:36

2 Answers2

1

I think you should first acquire a certificate file, and then use it in your code. For example, to set it for a SMTPClient object:

string certificate = "Certificate.cer";

X509Certificate cert = new X509Certificate2(certificate);

MailMessage message = new MailMessage(from, to);

SmtpClient client = new SmtpClient(server);

client.ClientCertificates.Add(cert);

client.Send(message);
Hamed
  • 1,175
  • 3
  • 20
  • 46
0

The web service that you are trying to connect to is using SSL/TLS. When you open the web service via internet explorer, it is giving you a warning that it cannot validate the certificate of the web service.

This has many reasons, and I guess in your case it is that the certificate that the web service is using is not for X.Y.Z.W.

Another reason could be that your machine does not trust the root issuer of the web service certificate. But from the error message that you have, I don't think this is the case.

You can view the certificate in IE by click on "Continue on this web site..", and the clicking on "Certificate Error", and the "View certificates".

enter image description here

From there, you will view the certificate. Go to details, and look for DNS Name inside Subject Alternative Name.

The DNS name is the name of the machine that the web service certificate was given for.

enter image description here

I guess in your case it will not be X.Y.Z.W.

Is the web service yours? can you obtain a different certificate for it? If so, can make sure you create a certificate that has the correct DNS name.

As a last resort, you can skip certificate validation from your code (this is not recommended). Take a look at this question.

Community
  • 1
  • 1
Yacoub Massad
  • 27,509
  • 2
  • 36
  • 62