如何从客户端应用程序运行Web服务的服务器的SSL证书? - C#.NET [英] How to get the SSL certificate of a server running a web service from the client app? - C# .NET
问题描述
我已经写在.NET 2.0的客户端程序,连接到Web服务。 我使用的Visual Studio来生成SoapHttpClientProtocol派生的类, 生成每一个方法就好了,一切正常。
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.
不过 - 网络服务正在运行只能通过HTTPS,所以我只是想知道,我怎么能得到服务器的证书的一个X509Certificate实例
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.
我知道这个框架做服务器的证书的验证透明的,所以我不需要去关心我的code中的证书验证,但我如果我需要阅读证书的序列号?
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?
在SoapHttpClientProtocol基类似乎只有成员/方法的客户端证书。
The SoapHttpClientProtocol base class seems to have only members/methods for client certificates.
感谢您的帮助
推荐答案
您挂钩到<一个href="http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback.aspx"相对=nofollow> ServicePointManager.ServerCertificateValidationCallback
。您的回调将与服务器的<一个被调用href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate.aspx"相对=nofollow> X509证书
,然后你可以检查任何你喜欢的就可以了,像<一个href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate.issuer%28VS.80%29.aspx"相对=nofollow> 发行人
和<一href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509certificate.getserialnumberstring%28VS.80%29.aspx"相对=nofollow> 的SerialNumber
。
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
.
这篇关于如何从客户端应用程序运行Web服务的服务器的SSL证书? - C#.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!