【问题标题】:What is analog for HttpListener in .NET Core.NET Core 中 HttpListener 的模拟是什么
【发布时间】:2017-10-12 14:14:25
【问题描述】:

我正在将应用程序从 .NET 4 移植到 .NET Core,但找不到 HttpListener 类的模拟

Error   CS0246  The type or namespace name 'HttpListener' could not be found (are you missing a using directive or an assembly reference?)  

更新1

        private readonly HttpListener _httpListener;

            if (!HttpListener.IsSupported)
        {
            throw new NotSupportedException(
                "The Http Server cannot run on this operating system.");
        }

        _httpListener = new HttpListener();
        _httpListener.Prefixes.Add(prefix);
        _sessionSettings = settings;

【问题讨论】:

标签: c# asp.net-core .net-core visual-studio-2017 asp.net-core-2.0


【解决方案1】:

如 cmets 中所述,WebListener(在 Microsoft.Net.Http.Server NuGet 包中)是最接近的替代品,但具有不同的 API。或者,还有 Kestrel HTTP 服务器,它最好从 ASP.NET Core 堆栈中使用,但可以单独使用(但这很难设置)。

如果你要移植,我建议等到 .NET Core 2.0,它有一个 API compatible HttpListener 可以跨平台工作,并且不需要你完全更改代码。

【讨论】:

  • 在收到AcceptAsync 的请求后,您有任何示例如何使用WebListener 发送响应吗?
【解决方案2】:

在 .NET Core 2.0 中我们没有这个问题(感谢 Martin Ullrich),所以现在我们需要安装 Visual Studio Preview 2017 version 15.3 以使用 .NET Core 2.0。

但默认情况下(目前最低)没有 .NET Core 2.0,安装 VS 2017 后我们需要 install it

P.S: - 再次感谢 Martin Ullrich - 太棒了,仅在 5 月 10 日(我提出要求前 3 天).NET Core 2.0 was announcing - 我现在拥有它

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多