Web Exception with Web Service
I have developed a client application to consume a web service,
there are no error's in my code however when I debug I get the following exception,
'WebException was unhandled - the underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.'
I think this is to do with the fact that it is a secure web service I am trying to consume, so my question is would this error occur due to the security certificate 开发者_运维问答not being installed correctly? And if so is there a way to manually instal the certificate into the application?
Thanks for your time.
This is basically an issue of missing trust. The server's ssl certificate needs to trusted by the consuming client. There are two ways to fix this:
Buy an SSL certificate from a trusted certificate authority (CA)
Add the server's SSL certificate to the Trusted People certificate store of the user running the app (or the computer on which the app is to be run (LocalMacine/TrustedPeople))
You can use the X509CertificateStore
class to add certificates to the appropriate store programmatically, so basically you can distribute the public key of the server's ssl certificate with your app and install it when needed.
I agree with @Klaus Byskov Hoffmann but would like to add on this his answer. This may also happen if the server domain name being used to access the service is not exactly the same as the certificate assigned to it. It creates an invalidity to the certificate even if both names apply to the machine.
精彩评论