[英]How to get the SSL certificate of a server running a web service from the client app? - C# .NET
I have a client program written in .NET 2.0, that connects to the web service. 我有一个用.NET 2.0编写的客户端程序,它连接到Web服务。 I used Visual Studio to generate a class derived from SoapHttpClientProtocol, every method was generated just fine, everything is working.
我使用Visual Studio生成一个派生自SoapHttpClientProtocol的类,每个方法都生成得很好,一切正常。
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. 但是 - Web服务只能通过HTTPS运行,所以我只是想知道,我怎么能得到服务器证书的X509Certificate实例。
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. SoapHttpClientProtocol基类似乎只有客户端证书的成员/方法。
Thanks for help 感谢帮助
You hook into the ServicePointManager.ServerCertificateValidationCallback
. 您挂钩到
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
. 您的回调将使用服务器的
X509Certificate
进行调用,您可以在其上检查您喜欢的任何内容,例如Issuer
和SerialNumber
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.