Hosting WebAPI using OWIN in a windows service

I was facing a similar issue. Below solution worked for me.

StartOptions options = new StartOptions();
options.Urls.Add("http://localhost:9095");
options.Urls.Add("http://127.0.0.1:9095");
options.Urls.Add(string.Format("http://{0}:9095", Environment.MachineName));

using (WebApp.Start<Program>(options))
{
    ...
}

Your machine's firewall could be blocking the incoming requests. You could do:

You could Run wf.msc command to open up Windows Firewall with Advanced Security and add a new Inbound Rule for TCP port 80.

(You should notice couple of inbound rules starting with World Wide Web Services.... These are for IIS. I am not sure if enabling these rules would be enough to even allow your windows service to receive the requests...you can try and see if this works otherwise as suggested before, you can create a new inbound rule..)

Update:
Based on your comment, it could be that because of your Url registrations you are unable to hit the service. Following are some examples of registering multiple urls with HttpListener.

StartOptions options = new StartOptions();
options.Urls.Add("http://localhost:9095");
options.Urls.Add("http://127.0.0.1:9095");
options.Urls.Add(string.Format("http://{0}:9095", Environment.MachineName));

using (WebApp.Start<Program>(options))
{

You can read more about the url registration in the following links:
http://technet.microsoft.com/en-us/library/bb630429.aspx
http://technet.microsoft.com/en-us/library/bb677364.aspx


There are 2 things that will prevent you from using anything different from "localhost" in Owin service:

  1. The app needs to run as admin in order to open a port with a different hostname as "localhost". You can fix this by either run the app with admin privileges or add an exception for a given port using: netsh http add urlacl url=http://*:9000/ user=<your user>
  2. The windows firewall may block traffic from other computers. In my case the firewall was not blocking local traffic (I could get to http://localhost:9000 or http://127.0.0.1:9000 or http://192.168.1.193:9000 - which was my local IP address from the same computer, but needed to add a port exception to the firewall to allow getting to this service from another computer)