I have created a simple self-hosted web api and a server that is basically a windows service.
Service has the following code:
protected override void OnStart(string[] args)
{
var config = new HttpSelfHostConfiguration("http://localhost:8085");
config.Routes.MapHttpRoute(
name: "API",
routeTemplate: "{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
HttpSelfHostServer server = new HttpSelfHostServer(config);
server.OpenAsync().Wait();
}
Web API
public class ValuesController : ApiController
{
public String GetString(Int32 id)
{
return "Test data";
}
}
Is there a way to do object sharing between the service and the web api? For example, connect to a database server in the service and use the connection object in web api etc.
Basically for this problem, I don't have any idea if this is possible and how. I searched on the internet but unable to reach the desired location.