简体   繁体   English

.NET Core 中 HttpListener 的模拟是什么

[英]What is analog for HttpListener in .NET Core

I'm porting application from .NET 4 to .NET Core and can't find analog for HttpListener class我正在将应用程序从 .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?)  

Update1更新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;

As mentioned in the comments, WebListener (in the Microsoft.Net.Http.Server NuGet package) is the closest replacement, but has a different API.如评论中所述, WebListener (在Microsoft.Net.Http.Server NuGet 包中)是最接近的替代品,但具有不同的 API。 Alternatively, there is the Kestrel HTTP server, which is best consumed from the ASP.NET Core stack but can be used alone (but that is difficult to set up).或者,还有 Kestrel HTTP 服务器,它最好从 ASP.NET Core 堆栈中使用,但可以单独使用(但这很难设置)。

If you are porting, I'd suggest to wait until .NET Core 2.0, which has an API compatible HttpListener that works cross-platform and doesn't require you to completely change the code.如果你要移植,我建议等到 .NET Core 2.0,它有一个兼容 API 的HttpListener ,可以跨平台工作,不需要你完全更改代码。

In .NET Core 2.0 we don't have that problem ( thanks Martin Ullrich), so now we need install Visual Studio Preview 2017 version 15.3 where we can use .NET Core 2.0.在 .NET Core 2.0 中我们没有这个问题(感谢 Martin Ullrich),所以现在我们需要安装Visual Studio Preview 2017 版本 15.3 ,我们可以在其中使用 .NET Core 2.0。

But by default (as minimum for now) there don't have .NET Core 2.0 and we need install it after VS 2017 installation.但默认情况下(目前最低)没有 .NET Core 2.0,我们需要在 VS 2017 安装后安装它

PS: - thanks again Martin Ullrich - it's amazing, only 10 May ( 3 days before I have asked) .NET Core 2.0 was announcing - and I have it now PS: - 再次感谢 Martin Ullrich - 太棒了,仅在 5 月 10 日(在我询问之前 3 天) 宣布了 .NET Core 2.0 - 我现在有了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM