Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
803 views
in Technique[技术] by (71.8m points)

.net - self signed cert. The underlying connection was closed: Could not establish trust relationship

Trying to set up a self signed certificate, for our intranet's web services site. The certificate itself shows it is "ok" but when trying to invoke a method from the web service it throws an error, and also while adding the web reference it gives a warning.

Here are the steps and some screenshots to make sure i provide accurate information.

Windows server 2003. IIS. The web site is "WebServices.companyName.vmc"

1

Here is the host header for the site

2

From the server, it shows the cert is 'ok'.

enter image description here

Here are some of the site settings

enter image description here


Now, in visual studio 2008, adding the web reference

enter image description here

Clicking 'Yes' to the popup

enter image description here

Clicking 'No' to this popup, several times sequentially.

enter image description here

After the line of code runs, which calls the web service... i get this error

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

And when webservice site in a browser, the little pad lock by the URL bar, provides this message:

enter image description here


Here is my existing code:

Dim mySvc As New WebServices.InstantAccount
mySvc.calledFunction()


EDIT

For anyone with a similar issue, please read both iamkrillin's answer, and my answer... as they are both two different ways of solving the issue... depending on which part you can control (the code, or the cert).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Add this line of code somewhere before you create your service client.

ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

Do note: this will cause your app to accept all invalid certs and just keep moving. If this is not acceptable, you can attach a function to that and do processing to determine if the cert error is ok or not


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...