I've self-hosted Web API using OWIN (inside a windows service). From what I understand, this is enough to make HTTP requests come to the windows service. I'm able to hit the WebAPI URL (http://localhost/users
) locally (from the same machine), but not from other machines. I'm using port 80, IIS is stopped. Other websites (hosted in IIS, on port 80) work fine when IIS is running.
//In the windows service:
public partial class Service1 : ServiceBase
{
...
...
protected override void OnStart(string[] args)
{
Console.WriteLine("Starting service...");
string baseAddress = "http://localhost:80/";
WebApp.Start<Startup>(baseAddress); //This is OWIN stuff.
}
...
...
}
public 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.
var config = new HttpConfiguration();
WebApiConfig.Register(config);
appBuilder.UseWebApi(config);
}
}
Do I need to do something more to get this working from other machines?
(I've a feeling that the incoming http requests are not being forwarded to the windows service, but only to IIS. When you hit locally, probably it does not go through the OS module that listens for http requests. Just a guess.)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…