提琴手:与'localhost'的连接失败。与owin selfhost

问题描述:

我有以下简单的控制台应用程序托管webapi使用欧文SelfHost。控制台本身的响应工作,但如果尝试从提琴手我只是得到一个连接到本地主机失败。 (与浏览器相同)。提琴手:与'localhost'的连接失败。与owin selfhost

class Program 
    { 
     static void Main() 
     { 
      string baseAddress = "http://localhost:34300/"; 
      Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("da-dk"); 
      // Start OWIN host 
      using (WebApp.Start<Startup>(url: baseAddress)) 
      { 
       // Create HttpCient and make a request to api/values 
       HttpClient client = new HttpClient(); 

       var response = client.GetAsync(baseAddress + "api/GpsPositions").Result; 

       Console.WriteLine(response); 
       Console.WriteLine(response.Content.ReadAsStringAsync().Result); 
       Console.WriteLine("Listening on " + baseAddress); 
      } 

      Console.ReadLine(); 
     } 
    } 

我错过了什么吗?

在使用块内部有Console.ReadLine();。没有这个网络应用程序将被丢弃。由于您正在使用块中的HttpClient拨打电话,因此在处理Web应用程序之前它可以正常工作。

+0

哈哈。卫生署。你是对的 – 2014-09-05 13:14:10

+0

Upvote如果你也陷入这个陷阱;) – piotrwest 2016-05-27 10:18:39