How to get the SSL certificate of a server running a web service from the client app? - C# .NET

StackOverflow https://stackoverflow.com/questions/1383992

문제

I have a client program written in .NET 2.0, that connects to the web service. I used Visual Studio to generate a class derived from SoapHttpClientProtocol, every method was generated just fine, everything is working.

But - the web service is running only through HTTPS, so I was just wondering, how could I get an X509Certificate instance of the server's certificate.

I know the Framework does the validation of the server's certificate transparently, so I dont need to care of the certificate validation in my code, but I what if I needed to read the certificate's serial number?

The SoapHttpClientProtocol base class seems to have only members/methods for client certificates.

Thanks for help

도움이 되었습니까?

해결책

You hook into the ServicePointManager.ServerCertificateValidationCallback. Your callback will be invoked with the server's X509Certificate and you can check anything you like on it, like the Issuer and SerialNumber.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top