.NET Core 中 HttpListener 的模拟是什么
What is analog for HttpListener in .NET Core
我正在将应用程序从 .NET 4 移植到 .NET Core,但找不到 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 核心堆栈中使用,但可以单独使用(但很难设置)。
如果您正在移植,我建议等到 .NET Core 2.0,它有一个 API compatible HttpListener
可以跨平台工作并且不需要您完全更改代码。
在 .NET Core 2.0 中我们没有这个问题(感谢 Martin Ullrich),所以现在我们需要安装 Visual Studio Preview 2017 version 15.3 以便我们可以使用 .NET Core 2.0。
但默认情况下(目前最低)没有 .NET Core 2.0,我们需要 install it 安装 VS 2017 后。
P.S:- 再次感谢 Martin Ullrich - 太棒了,只有 5 月 10 日(我问的前 3 天).NET Core 2.0 was announcing - 我现在有了它
我正在将应用程序从 .NET 4 移植到 .NET Core,但找不到 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 核心堆栈中使用,但可以单独使用(但很难设置)。
如果您正在移植,我建议等到 .NET Core 2.0,它有一个 API compatible HttpListener
可以跨平台工作并且不需要您完全更改代码。
在 .NET Core 2.0 中我们没有这个问题(感谢 Martin Ullrich),所以现在我们需要安装 Visual Studio Preview 2017 version 15.3 以便我们可以使用 .NET Core 2.0。
但默认情况下(目前最低)没有 .NET Core 2.0,我们需要 install it 安装 VS 2017 后。
P.S:- 再次感谢 Martin Ullrich - 太棒了,只有 5 月 10 日(我问的前 3 天).NET Core 2.0 was announcing - 我现在有了它