Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Update1

        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;
like image 901
Alexander Avatar asked May 13 '17 09:05

Alexander


People also ask

What does HttpListener do?

Using the HttpListener class, you can create a simple HTTP protocol listener that responds to HTTP requests.

What is HttpListener C#?

The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web. HttpListener is a simple, programmatically controlled HTTP protocol listener. It can be used to create HTTP servers.

What is as net core?

ASP.NET Core is a cross-platform, high-performance, open-source framework for building modern, cloud-enabled, Internet-connected apps. With ASP.NET Core, you can: Build web apps and services, Internet of Things (IoT) apps, and mobile backends. Use your favorite development tools on Windows, macOS, and Linux.


2 Answers

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).

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.

like image 69
Martin Ullrich Avatar answered Sep 19 '22 14:09

Martin Ullrich


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.

But by default (as minimum for now) there don't have .NET Core 2.0 and we need install it after VS 2017 installation.

P.S: - thanks again Martin Ullrich - it's amazing, only 10 May ( 3 days before I have asking) .NET Core 2.0 was announcing - and I have it now

like image 29
Alexander Avatar answered Sep 19 '22 14:09

Alexander