title: Configuring SSL on ASP.NET Self-Hosted Web API
body: <p>I'm creating Self-hosted Web API service. To secure it, I've studied and implemented <a href="http://www.codeproject.com/Articles/630986/Cross-Platform-Authentication-With-ASP-NET-Web-API#_rating">this</a> article, successfully generated an local SSL Certificate using makecert and my service authenticated and generates tokens fine, if I'm using </p>
  
  <pre><code>http://localhost/webapi/authentication/authenticate
  </code></pre>
  
  <p>link, but when I try to access my service using HTTPS, I get following on Firefox:</p>
  
  <blockquote>
    <p>ssl_error_rx_record_too_long</p>
  </blockquote>
  
  <p>and for the same request Fiddler shows me:</p>
  
  <blockquote>
    <p>HTTP/1.1 502 Fiddler - Connection Failed Date: Mon, 26 Aug 2013
    10:44:27 GMT Content-Type: text/html; charset=UTF-8 Connection: close
    Timestamp: 13:44:27.433</p>
    
    <p>[Fiddler] The socket connection to localhost failed.  <br />Failed to
    negotiate HTTPS connection with server.fiddler.network.https&gt;
    Failed to secure existing connection for localhost. The handshake
    failed due to an unexpected packet format..</p>
  </blockquote>
  
  <p>My self-host configuration:</p>
  
  <pre><code>    private HttpSelfHostServer _server;
      private ExtendedHttpsSelfHostConfiguration _config;
      public const string ServiceAddress = "https://localhost/webapi";
      _config = new ExtendedHttpsSelfHostConfiguration(ServiceAddress);
      _server = new HttpSelfHostServer(_config);
      _server.OpenAsync();
  </code></pre>
  
  <p>where ExtendedHttpSelfHostConfiguration taken from <a href="https://pfelix.wordpress.com/2012/02/26/self-hosting-asp-net-web-api/">this post</a> is:</p>
  
  <pre><code>public class ExtendedHttpSelfHostConfiguration : HttpSelfHostConfiguration
  {
      public ExtendedHttpSelfHostConfiguration(string baseAddress) : base(baseAddress) { }
      public ExtendedHttpSelfHostConfiguration(Uri baseAddress) : base(baseAddress) { }
  
      protected override BindingParameterCollection OnConfigureBinding(HttpBinding httpBinding)
      {
          if (BaseAddress.ToString().ToLower().Contains("https://"))
          {
              httpBinding.Security.Mode = HttpBindingSecurityMode.Transport;
          }
  
          return base.OnConfigureBinding(httpBinding);
      }
  }
  </code></pre>
  
  <p>What I'm missing?
  Thanks in advance!</p>