Could not establish trust relationship for the SSL/TLS secure channel

Was trying to develop a test app. that interfaces to webservice hosted under SSL but prompted error as stated in topic. There wasn’t any issue if the app. connects to function hosted by webservice without SSL. A further checking, the certificate used by the webservice has already expired (since the certificate was generated as test during initial setup) and no longer being updated. Thinking not to touch the web server on the SSL configuration, I thought I should come up with a workaround instead since normal web browser access works just fine even if the certificate is expired or invalid.

One workaround which I can find in Microsoft forum, to overwrites the handler function of when accepting certificate from the server through (ServicePointManager.ServerCertificateValidationCallback). A snippet of the code as below:

Private Function ValidateCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean
‘Return True to force the certificate to be accepted.
Return True
End Function

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)
End Sub

For more in-depth explanation, refer to Microsoft Support.

Written by admin on May 14th, 2012 with no comments.
Read more articles on Programming and Web.

Related articles

No comments

There are still no comments on this article.

Leave your comment...

If you want to leave your comment on this article, simply fill out the next form:




You can use these XHTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .