I am using the below code to start a web server that should be open to listen always but it is executing only once, I am deploying this in AKS – the container is not staying in running state, it is exiting after completing the job i.e., printing the response.
Please help me understand where I am doing wrong or my understanding itself is not right.
May be this is not the right piece of code to use if I want the container to be always running as a web server that listens to requests from other apps in the project.
string baseAddress = "http://localhost:9000/";
// Start OWIN host
using (WebApp.Start<Startup>(url: baseAddress))
{
// Create HttpClient and make a request to api/values
HttpClient client = new HttpClient();
var response = client.GetAsync(baseAddress + "api/values").Result;
System.Console.WriteLine(response);
System.Console.WriteLine(response.Content.ReadAsStringAsync().Result);
System.Console.ReadLine();
}
2
Answers
If you want to listen incoming
http
requests, try something like that withHttpListener
:If your code is already working for once. Thats should be help for loop