简体   繁体   English

如何从客户端应用程序获取运行Web服务的服务器的SSL证书? - C#.NET

[英]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进行调用,您可以在其上检查您喜欢的任何内容,例如IssuerSerialNumber

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用C#的客户端证书调用Web服务? - How to call web service with client certificate from C#? 如何从php客户端调用C#.NET Web服务 - how to call a C# .NET web service from a php client 从.net客户端访问ssl服务器(Web服务) - Accessing ssl server (web service) from .net client Rest Client C#的Web.config中的SSl证书详细信息 - SSl certificate details in Web.config of Rest Client C# 使用通配符证书的SSL上的C#Web服务调用(asmx) - C# Web Service Call (asmx) over SSL with wildcard certificate c#调用Web服务错误:“未提供客户端证书。 在客户端凭据中指定客户端证书” - c# calling web service error: “The client certificate is Not provided. Specify a client certificate in client credentials” 通过在服务帐户下运行的Web服务将用户名从C#本机应用程序传递到SQL Server的好方法 - Good ways to pass user name from C# native app to SQL Server via a web service running under a service account 如何在Web服务C#中获取客户端计算机的Internet地址 - how to get the internet Address of client machine in the Web service C# C#从ServerCertificateValidationCallback获取SMTP服务器的SSL证书到期日期作为返回值 - C# Get SSL-Certificate expiration date of SMTP-Server as return value from ServerCertificateValidationCallback 使用 c# 使用证书进行 SSL 客户端身份验证 - SSL Client Authentication with certificate using c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM