I managed to run my self hosted WEP API using OWIN in a console application by starting it with a code like this:
//string baseAddress = "http://192.168.1.6:8111/";
string baseAddress = "http://+:8111/";
// Start OWIN host
using (Microsoft.Owin.Hosting.WebApp.Start<Startup>(url: baseAddress))
{
Console.ReadLine();
}
By using and registering an address like "http://+:9000/" on the service host machine the idea was to use a generic IP address for the host that would not affect the clients when the IP of the host might change.
The clients are on other machines than the one that is running the service. Something like a mobile phone from the LAN or another laptop from the LAN, and in the future if possible also outside the LAN.
In the client of my self hosted service, which is a html page, I have a JavaScript code like:
//var uri = 'http://192.168.1.6:8111/api/tests';
var uri = 'http://+:8111/api/tests';
function Read()
{
$.getJSON(uri + '/' + id)
}
By using the static commented IP address of the host in the client I can get to the self hosted WEB API but when I try to use the generic one "http://+:9000/api/tests" it fails to connect to the service.
Is there a way to connect from the client to the service by using such a generic configuration ? or how should I configure the service host machine and the client so that an IP change on the host will not stop the service on the client machine ?
I need to take into account that the IP address of my self hosted machine might change and the clients will lose the connection since they will use an old outdated IP address of the service host machine.
If the clients are within the same LAN you can request the host by name instead of IP address.
To find the host name, open a command prompt on the host machine and type: hostname
It will show the host name, for example myhost
. Then you can request it as http://myhost:8111
or whatever the port is.
For clients outside of your LAN you have to use DNS. Or connect via VPN if that's an option.