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.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(AddressOf ValidateCertificate)
For more in-depth explanation, refer to Microsoft Support.