title: Reading certificate hash from remote server
body: <p>I receive an error when trying to get a certificate hash from a remote machine using the following code:</p>
  
  <pre><code>private string getCertHash(string Hostname)
  {
      string result = "";
  
      using (ServerManager serverManager = ServerManager.OpenRemote(Hostname))
      {
          SiteCollection siteCollection = serverManager.Sites;
          foreach (Site site in siteCollection)
          {
              foreach (Binding binding in site.Bindings)
              {
                  if (binding.Protocol == "https")
                  {
                      // Error here
                      foreach (Byte certhashbyte in binding.CertificateHash)
                          result += certhashbyte.ToString(); 
                  }
              }
          }
      }
  
      return result;
  }
  </code></pre>
  
  <p>The error I receive in more detail:</p>
  
  <blockquote>
    <p>'binding.certhashbyte' threw an exception of type
    'System.Runtime.InteropServices.COMException'</p>
    
    <p>Either the application has not called WSAStartup, or WSAStartup
    failed. (Exception from HRESULT: 0x8007276D)</p>
  </blockquote>
  
  <p>If I replace the following row:</p>
  
  <pre><code>using (ServerManager serverManager = ServerManager.OpenRemote(Hostname))
  </code></pre>
  
  <p>with </p>
  
  <pre><code>using (ServerManager serverManager = new ServerManager)
  </code></pre>
  
  <p>to use the local server it works fine. </p>
  
  <p>Note that using ServerManager.OpenRemote(Hostname) works in general (I get all the other information, just the CertHash info results in an error. I have admin rights on both machines (local and remote). System is Windows 2008 R2 using IIS 7.5.</p>
  
  <p>Please tell me what I'm doing wrong / what is missing / why the error occurs.</p>