Thursday, March 26, 2020

Hosting Restful services on Windows service using OWIN


Hosting Restful services on Windows service using OWIN

Code:

public partial class Service : ServiceBase
{
protected override void OnStart(string[] args)
        {
            StartOptions options = new StartOptions();
           options.Urls.Add("http://+:9889/DPE");
            _startup = WebApp.Start<OwinStartup>(options);
        }
}


Steps on server:

1.       Open command prompt in Administration mode.
2.      Run netsh show command and redirect output to another txt file
e.g.,netsh http show urlacl >"netsh_registeredurls.txt"
=>Displays/outputs the registered urls in the HTTP.sys settings
3.      If particular port present, delete all entries using netsh http delete command
e.g., netsh http delete urlacl url=http://+:9889/
4.      Uninstall service
5.      Add registered entry in HTTP.sys
e.g., netsh http add urlacl url=http://+:9889/ user=jeder (Note: jeder is Germany equivalent of Everyone)
6.      Install service
7.      Launch service