6

である私は、.NETのコアへの.NET 4からアプリケーションを移植していますし、HttpListenerをクラス.NETのコアで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; 
+0

WebListenerそれを持っていますか? https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/weblistener –

+0

また、githubにいくつかの簡単なライブラリがありますhttps://github.com/robertsundstrom/HttpListener –

+0

突然両方(WebListenerとgithub .com/robertsundstrom/HttpListener)にはいくつかのプロパティがありません。互換性がないため、 – Alexander

答えて

5

.NET Core 2.0ではこの問題はありません(Martin Ullrichありがとう)ので、.NET Core 2.0を使用できる場所にVisual Studio Preview 2017 version 15.3をインストールする必要があります。

デフォルトでは(現在のところ最小限)、.NET Core 2.0はなく、VS2017のインストール後にinstall itが必要です。

P.S: - おかげで再びマーティン・ウルリッヒが - それは、唯一の5月10日、.NETのコア2.0 was announcingを(私が求めてきた3日前に)驚くべきことだ - と私は今

11

としてのためのアナログ見つけることができませんコメントの中のWebListenerMicrosoft.Net.Http.Server NuGetパッケージ内)が最も近いが、別のAPIを持っている。代わりに、Kestrel HTTPサーバがあります。これはASP.NET Coreスタックから最もよく消費されますが、単独で使用することもできます(ただし、セットアップは困難です)。

移植する場合は、クロスプラットフォームで動作するAPI互換HttpListenerを持つ.NET Core 2.0まで待つことをお勧めします。コードを完全に変更する必要はありません。

+0

'AcceptAsync'でリクエストを取得した後、' WebListener'でレスポンスを送信する方法がありますか? – DixonD

関連する問題