我遵循了http://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api的一步一步的指示.
以下是控制台应用程序的代码:
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" };
}
}
}
以下是事实:
我遇到的问题:
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
我尝试了以下几项,但没有成功:
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'
发布于 2015-09-09 06:58:32
使用基本地址http://+:1961/
,并取决于您正在运行自己的服务器的windows帐户,因为您不需要urlacl
。ie:
local system
帐户将您自己的服务器作为windows服务运行,那么您将不需要urlacl。https://stackoverflow.com/questions/26006284
复制