Home > other >  Get server certificate details
Get server certificate details

Time:10-15

My application consumes web service via HTTPS. How to get more details about server certificate like organization name, serial number ant similar info? This information is needed just for learning purposes.

   ServiceReference2.WebService1SoapClient srv = new ServiceReference2.WebService1SoapClient();
    String s = srv.HelloWorld();
    Console.WriteLine(s);

CodePudding user response:

this post is a little old but it should still apply your scenario: How to get the SSL certificate of a server running a web service from the client app? - C# .NET

ServicePointManager.ServerCertificateValidationCallback would provide enough information on the cert from the remote server.

There are samples you might find interesting on the MSDN page.

Like:

// The following method is invoked by the RemoteCertificateValidationDelegate.
public static bool ValidateServerCertificate(
      object sender,
      X509Certificate certificate,
      X509Chain chain,
      SslPolicyErrors sslPolicyErrors)
{
   if (sslPolicyErrors == SslPolicyErrors.None)
        return true;

    Console.WriteLine("Certificate error: {0}", sslPolicyErrors);

    // Do not allow this client to communicate with unauthenticated servers.
    return false;
}

Notice the certificate parameter on the delegate. The delegate must be passed to the ServicePointManager.ServerCertificateValidationCallback static property before executing the http call.

  • Related