1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Web.Http.SelfHost;
- namespace XdCxRhDW.App.WebAPI
- {
- public class RestApiServer
- {
- public const int PORT = 8091;
- private static HttpSelfHostServer _server;
- public static void StartUp()
- {
- string host = string.Empty;
- host ="127.0.0.1";
- try
- {
- if (_server != null)
- {
- _server.CloseAsync().Wait();
- _server.Dispose();
- _server = null;
- }
- string baseAddress = $"http://{host}:{PORT}";
- var config = new HttpSelfHostConfiguration(baseAddress);
- Console.WriteLine();
- Routes.ConfigureRoutes(config);
- Console.WriteLine("Instantiating The Server...");
- _server = new HttpSelfHostServer(config);
- _server.OpenAsync().Wait();
- Console.WriteLine("Server is Running Now and listen : " + baseAddress);
- }
- catch (Exception e)
- {
- throw e;
- }
- }
- public static void ShutDown()
- {
- if (_server != null)
- {
- _server.CloseAsync();
- _server.Dispose();
- }
- }
- }
- }
|