20

So, we have a large program which uses HttpListener for a small remote admin feature. For reasons I don't understand, some people have issues with a 503 error.

Since we're not supplying the error, there's something happening in the framework. Now, my question is, what inside the framework supplies this error? Is it that the prefixes aren't set properly or something?

We currently have our prefix set as "http://*:8080/".

Advice?

RandomInsano
  • 1,204
  • 2
  • 16
  • 36

3 Answers3

31

I've got same error on Windows 7, when trying to set permissions for HttpListener using netsh http command. On target system run the command (valid for Windows 7):

netsh http show urlacl    

and check, if your URL "http://+:8080/" already presented in reserved urls list. Try to remove from list (using "netsh http delete urlacl". Similar topic here.

Community
  • 1
  • 1
apdevelop
  • 598
  • 6
  • 19
  • 1
    Great answer, I had the same problem: one of my test used the HttpSelfHostConfiguration class which required to reserve the url it used (via netsh) while another test that used the HttpListener threw HTTP 503 error when I wanted to access it, because the url was reserved beforehand by the first test. – Márk Gergely Dolinka Sep 09 '13 at 10:56
  • I had the same problem (503 error) trying to reach a HttpListener running on a custom port. I found the URL after running `show urlacl` and removed it with `delete urlacl [custom URL:port]`. After that it worked. Thanks. – walterpaoli Jan 24 '18 at 15:00
  • it works, but why after close my application that use the URL even after restart windows the URL still reserved? – luis alberto juarez Dec 05 '19 at 16:22
  • Because reserved URL list is system-wide and doesn't depends on any process running state. – apdevelop Dec 06 '19 at 13:29
  • 1
    yes, i do this: 【`netsh http add urlacl url=http://*:8080/ user=everyone listen=yes`】 and 【`netsh http delete urlacl url=http://+:8080/`】, it work for me! – Elon Jun 29 '21 at 14:17
  • Thank you, that solved my problem! Needed to reboot the machine after deleting the gratuitous urlacl though. – Klaws Mar 25 '23 at 08:40
6

I'm a bit late to the question. But I just faced the HTTP 503 status code in the following case:

If, for example, there is "http://+:8080/MyService/" and "http://+:8080/MyService/SOAP" registered using netsh http add urlacl, we receive 503 for requests targeting an ambiguous URL. Requests for "http://myservice:8080/MyService/somethingelse" worked fine, while requests for "http://myservice:8080/MyService/SOAP/" failed with status 503.

Added this for completeness. Took me a while to figure out.

uebe
  • 488
  • 4
  • 11
0

Make sure your HttpListener and urlacl match.

Starting your listener as (C#):

using System;
using System.Net;
using System.ServiceModel;

namespace Example
{
    class MyApi
    {
        private const int _apiPortNumber = 8080;
        public const string BasePath = "/myApi/";
        public static EndpointAddress MyEndPoint => new EndpointAddress(
            new UriBuilder(
                    Uri.UriSchemeHttp,
                    "localhost",//only allow connections on localhost (no remote access)
                    _apiPortNumber,
                    BasePath)
                .Uri);

        public MyApi()
        {
            var httpListener = new System.Net.HttpListener();
            httpListener.Prefixes.Add(MyEndPoint.Uri.ToString());
            httpListener.Start();
        }
    }
}

What works as your urlacl is:

netsh http add urlacl url=http://127.0.0.1:8080/myApi/ user=MyServiceUserName

However configuring your urlacl as follows will NOT work:

http add urlacl url=http://+:8080/myApi/ user=MyServiceUserName

Martin
  • 113
  • 5