HttpListener server returns error: (503) Service unavailable

I am trying to create an HTTP listener that uses x509 certificates for client / server authentication.

My server code is as follows.

_listener = new HttpListener();
_listener.Prefixes.Add("https://localhost:8006/");
_listener.Start();
HttpListenerContext context = _listener.GetContext();

My client code is as follows

string url = "https://localhost:8006/";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
var store = new X509Store(StoreName.TrustedPeople, StoreLocation.LocalMachine);
store.Open(OpenFlags.ReadOnly);
var cert = store.Certificates.Find(X509FindType.FindBySubjectName, "localhost", true);
request.ClientCertificates.Add((X509Certificate)cert[0]);
ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, policyErrs) =>
   {
       return policyErrs == System.Net.Security.SslPolicyErrors.None;
   };
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

I believe that everything is set up correctly. There are no certificate policy errors, I have bound the ssl certificate to the port and do not require any elevated permissions to start the listener.

enter image description here

If I make a web request in code or through Chrome, I get this error. What am I doing wrong here?

enter image description here

0
source share
1 answer

, 'localhost' '+', .

+2

All Articles