0

I'm using Owin and Topshelf to selfhost an ASP.net Web Api.

I am able to access it through localhost and 127.0.0.1 on the device that is self hosting it. The idea is that any device that comes onto the network and has my computer or mobile application installed is able to communicate with that web api to request/update/remove data from the database hanging behind.

The issue i am having is that i have no way of finding out on what internal ip the service is actually running. I have no control/view over the network that it's installed onto (except through my code), this means i don't know what the ip or hostname might be, only the port number (on any other device that isn't hosting it).

I tried adding custom url's like shown below

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

Obviously localhost and 127.0.0.1 won't work for a remote device on the same network. The issue with the MachineName is that i don't have a say in the name of the machine either, meaning this could be anything. I assumued the wildcard would allow me to send a request on port 6969 and the host would catch it, this was sadly not the case.

This leaves me in a bit of an issue, i now have a self hosted Web api, on a machine with a random ip and name, and it needs to be accessed by other devices on the same network, The users are not able to manually enter ip, and i can't force a name onto the host computer. This all leaves me in a situation where im not sure wat else i could try, or if its even possible to reach the host computer without human interference.

Edit: I did come across something along the lines of a

network broadcast address Which should in someway allow me to send out a message from a device, and let the server respond with its ip. Not sure how i would apply this to my self hosted web api though.

Black Lotus
  • 2,377
  • 3
  • 14
  • 18
  • Can you not have the service report its address to another discovery service and you have the client query the discovery service to obtain the address to the web API service? – junkangli Apr 10 '18 at 22:30
  • @junkangli Please elaborate, i am not familiar with the discovery service. Am i suppose to run another self hosted service in some way, that is discoverable? – Black Lotus Apr 10 '18 at 22:37

1 Answers1

0

Basically, the idea is to have your web API application register its address to a service, such as DNS, which may be updating the IP address of a DNS A record. Then clients will query this service or DNS, to resolve the address to your application.

junkangli
  • 1,152
  • 7
  • 14
  • Would i be able to do this locally? Since the application will be distributed, and i won't be doing the installations, but users them self, and alot of them dont even have the network attached to the outside world, it needs to be something that works internally, besides that i obviously can't register every user to a domain. – Black Lotus Apr 10 '18 at 23:16