Quantcast
Channel: Web API
Viewing all articles
Browse latest Browse all 4850

How to start and stop web api when self host in windows service

$
0
0

windows service has start and stop function. from win service start function we like to start web api like this way

string baseAddress = "http://localhost:9000/";

            // Start OWIN host 
            using (WebApp.Start<Startup>(url: baseAddress))
            {
                // Create HttpCient and make a request to api/values 
                HttpClient client = new HttpClient();
                HttpResponseMessage response = client.GetAsync(baseAddress + "api/Values/TestGet1").Result;
                response.Headers.Remove("Server");
                Console.WriteLine(response);
                Console.WriteLine(response.Content.ReadAsStringAsync
                    ().Result);
                Console.ReadLine();
            }

but how to stop the service when stop function will fire in windows service ?

i am looking for complete small code.


Viewing all articles
Browse latest Browse all 4850

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>