在EC2上使用OWIN自托管Web API [英] Self hosting Web API with OWIN on EC2

查看:99
本文介绍了在EC2上使用OWIN自托管Web API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照这是控制台应用程序的代码:

Here is the code of console application:

namespace OWINTest
{
class Program
  {
    static void Main(string[] args)
    {
        string baseAddress = "http://localhost:1961/";
        // Start OWIN host 
        WebApp.Start<Startup>(url: baseAddress);
        ...
    }
  }
class Startup
  {
    // This code configures Web API. The Startup class is specified as a type
    // parameter in the WebApp.Start method.
    public void Configuration(IAppBuilder appBuilder)
    {
        // Configure Web API for self-host. 
        HttpConfiguration config = new HttpConfiguration();
        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        appBuilder.UseWebApi(config);
    }
  }
public class ValuesController : ApiController
  {
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }
  }
}

以下是正确的:

  1. OWIN服务器正在运行(可以使用Fiddler,浏览器从同一台计算机连接)
  2. EC2实例的端口已通过安全组打开以接受入站流量
  3. 没有其他进程在监听该端口
  4. OWIN版本是Microsoft.AspNet.WebApi.OwinSelfHost 5.2.2
  5. .NET 4.5已安装在EC2实例上

问题我碰到了

HTTP/1.1 502 - Connection Failed error when calling http://(uc2-00-000-000-us-west-1.compute.amazonaws.com):1961/api/values with the following message: The connection to 'ec2-00-000-000-us-west-1.compute.amazonaws.com' failed. Error: TimedOut (0x274c). System.Net.Sockets.SocketException A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 

我尝试了以下操作但未成功:

I tried the following without success:

 1. 'netsh http add urlacl url=http://localhost:1961 user=everyone'
 2. 'netsh http add urlacl url=http://+:1961 user=everyone'
 3. 'netsh http add urlacl url=http://*:1961 user=everyone'

推荐答案

使用基本地址http://+:1961/,并根据运行Windows owin服务器的Windows帐户,因为您不需要urlacl. 即:

Use base address http://+:1961/ and depending on which windows account you are running your owin server as you won't need the urlacl. ie:

  • 您正在使用local system帐户将owin服务器作为Windows服务运行,那么您将不需要urlacl.
  • 您在登录管理员帐户时正在命令提示符下运行owin服务器.
  • you're running your owin server as a windows service using the local system account then you won't need the urlacl.
  • you're running the owin server from the command prompt while logged in the administrator account.

这篇关于在EC2上使用OWIN自托管Web API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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