什么原因导致HttpListener HTTP 503错误?

时间:2011-11-15 20:00:38

标签: c# httplistener

因此,我们有一个大型程序,它使用HttpListener进行小型远程管理功能。由于我不理解的原因,有些人遇到503错误的问题。

由于我们没有提供错误,因此框架中发生了一些事情。现在,我的问题是,框架内部提供了什么错误?是不正确设置前缀还是什么?

我们目前的前缀设置为“http:// *:8080 /”。

么?

3 个答案:

答案 0 :(得分:21)

尝试使用netsh http命令设置HttpListener的权限时,我在Windows 7上遇到了同样的错误。 在目标系统上运行命令(对Windows 7有效):

netsh http show urlacl    

并检查您的网址“http://+:8080/”是否已在保留网址列表中显示。尝试从列表中删除(使用“netsh http delete urlacl”。类似主题here

答案 1 :(得分:4)

我对这个问题有点迟了。但在下列情况下我只是面对HTTP 503状态代码:

例如,如果使用netsh http add urlacl注册了“http://+:8080/MyService/http://+:8080/MyService/SOAP”,则针对不明确的网址的请求会收到503。对“http://myservice:8080/MyService/somethingelse”的请求工作正常,而对“http://myservice:8080/MyService/SOAP/”的请求失败,状态为503。

为完整性添加了此内容。我花了一段时间才弄明白。

答案 2 :(得分:0)

确保您的HttpListenerurlacl匹配。

以(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();
        }
    }
}

作为您的urlacl起作用的是:

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

但是按以下方式配置urlacl无效:

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

相关问题