title: Accessing a web service and a HTTP interface using certificate authentication
body: <p>It is the first time I have to use certificate authentication.
  A commercial partner expose two services, a XML Web Service and a HTTP service. I have to access both of them with .NET clients.</p>
  
  <p><strong>What I have tried</strong></p>
  
  <p><strong>0. Setting up the environment</strong></p>
  
  <p>I have installed the SSLCACertificates (on root and two intermediate) and the client certificate in my local machine (win 7 professional) using certmgr.exe.</p>
  
  <p><strong>1. For the web service</strong></p>
  
  <ul>
  <li>I have the client certificate (der).</li>
  <li>The service will be consumed via a .NET proxy.</li>
  </ul>
  
  <p>Here's the code:</p>
  
  <pre><code>OrderWSService proxy = new OrderWSService();
  string CertFile = "ClientCert_DER.cer";
  
  proxy.ClientCertificates.Add(new System.Security.Cryptography.X509Certificates.X509Certificate(CertFile));
  orderTrackingTO ot = new orderTrackingTO() { order_id = "80", tracking_id = "82", status = stateOrderType.IN_PREPARATION };
  resultResponseTO res = proxy.insertOrderTracking(ot);
  </code></pre>
  
  <p>Exception reported at last statement: <code>The request failed with an empty response</code>.</p>
  
  <p><strong>2. For the HTTP interface</strong></p>
  
  <ul>
  <li>it is a HTTPS interface I have to call through POST method.</li>
  <li>The HTTPS request will be send from a .NET client using HTTPWebRequest.</li>
  </ul>
  
  <p>Here's the code:</p>
  
  <pre><code>string PostData = "MyPostData";
  
  //setting the request
  HttpWebRequest req;
  req = (HttpWebRequest)HttpWebRequest.Create(url);
  req.UserAgent = "MyUserAgent";
  req.Method = "POST";
  req.ContentType = "application/x-www-form-urlencoded";
  req.ClientCertificates.Add(new System.Security.Cryptography.X509Certificates.X509Certificate(CertFile, "MyPassword")); 
  
  //setting the request content
  byte[] byteArray = Encoding.UTF8.GetBytes(PostData);
  Stream dataStream = req.GetRequestStream();
  dataStream.Write(byteArray, 0, byteArray.Length);
  dataStream.Close();
  
  //obtaining the response
  WebResponse res = req.GetResponse();
  r = new StreamReader(res.GetResponseStream());
  </code></pre>
  
  <p>Exception reported at last statement: <code>The request was aborted: Could not create SSL/TLS secure channel</code>.</p>
  
  <p><strong>3. Last try: using the browser</strong></p>
  
  <p>In Chrome, after installing the certificates, if I try to access both urls I get a 107 error:</p>
  
  <pre><code>Error 107 (net::ERR_SSL_PROTOCOL_ERROR)
  </code></pre>
  
  <p>I am stuck.</p>