8

I've created a windows service using Owin and topshelf.
the application is a WebAPI that listens on port 9000 and I have allowed this port in my firewall rules.
when I executed the .exe file on windows server 2008 I can use it locally(localhost:9000)
but when I try to access it from other machines, I get this error message:

HTTP Error 400. The request hostname is invalid

what am I missing? please help.

Mohsen Shakiba
  • 1,762
  • 3
  • 22
  • 41

2 Answers2

18

this solved my problem, which might be super obvious to you, but not as much to me.
instead of using this code:

WebApp.Start("http://localhost:8080/");

I had to use this:

WebApp.Start("http://*:8080/");

of course one shouldn't forget to open the port in the firewall too.

Mohsen Shakiba
  • 1,762
  • 3
  • 22
  • 41
  • This fixed it for me, though the app now has to run with Administrator permissions - so it's not so easy to debug. when running as a service it's using 'Local System' and that seems fine, so it's working at least. – GPW Nov 29 '17 at 16:55
0

Maybe a hosts entry on the remote machine? remember that "localhost" points to the current machine itself. You may need to set up a local IIS server, deploy your WebApi to that, so that other computers can see it.

Incidentelly, there is no way for your ASP.Net development server (Visual Studio's built-in server) to serve other pages than localhost, so you may need to trick it using something like Fiddler or Cassini to act as a route during debug.

There are some related answers to this here: Can I access ASP.NET Development server in an intranet?

I hope it helps you

Community
  • 1
  • 1
Pedro G. Dias
  • 3,162
  • 1
  • 18
  • 30
  • but what if I want to use self host? – Mohsen Shakiba Mar 05 '16 at 07:20
  • You mean with Kestrel or something? Sure that should work too. The big thing is only that Visual Studio's development environment does NOT give you anything other than "localhost" address, so even with firewalls open, it won't work. – Pedro G. Dias Mar 05 '16 at 07:23
  • I mean with owin self host. I heard with owin you don't need IIS anymore – Mohsen Shakiba Mar 05 '16 at 07:30
  • this isn't related to the OP's question. He's not trying to connect to VS's Server, he's trying to connect to an OWIN self-hosted API using topshelf to run as a service. – GPW Nov 29 '17 at 16:56