我使用OWIN(在Windows服务内部)自托管Web API。据我所知,这已足以使HTTP请求传达到Windows服务。我可以从本地(同一台计算机)访问WebAPI URL (http://localhost/users
),但其他计算机无法访问。我使用的是端口80,IIS已停止。当IIS运行时,其他网站(在端口80上托管于IIS中)可以正常工作。
//在Windows服务中:
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);
}
}
我需要做更多的事情才能使它在其他机器上运行吗?(我有一种感觉,传入的http请求没有被转发到Windows服务,而是仅转发到IIS。当您在本地访问时,可能不会通过侦听http请求的操作系统模块进行处理。这只是一个猜测。)