.NET Core 中 HttpListener 的模拟是什么 [英] What is analog for HttpListener in .NET Core

查看:23
本文介绍了.NET Core 中 HttpListener 的模拟是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm porting application from .NET 4 to .NET Core and can't find analog for HttpListener class

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;

推荐答案

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

As mentioned in the comments, WebListener (in the Microsoft.Net.Http.Server NuGet package) is the closest replacement, but has a different 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).

如果您要移植,我建议等到 .NET Core 2.0,它有一个 API 兼容 HttpListener 跨平台工作,不需要你完全改变代码.

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 中 HttpListener 的模拟是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆