static void Main(string[] args) { var config = new HttpSelfHostConfiguration("http://localhost:8080"); bool isolateAreaSwaggers; bool.TryParse(ConfigurationManager.AppSettings["isolateAreaSwaggers"], out isolateAreaSwaggers); SwaggerConfig.Register(config, isolateAreaSwaggers); WebApiConfig.Register(config); using (var server = new HttpSelfHostServer(config)) { server.OpenAsync().Wait(); Console.WriteLine("Press Enter to quit."); Console.ReadLine(); } }
static void main(string[] args) { // Configure Web API for self-host. var config = new HttpSelfHostConfiguration("http://localhost:1010/Values/DATA"); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); using (HttpSelfHostServer server = new HttpSelfHostServer(config)) { server.OpenAsync().Wait(); Console.WriteLine("Self Host Started.."); Console.ReadLine(); } }
static void Main(string[] args) { var config = new HttpSelfHostConfiguration(baseAddress); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); using (var server = new HttpSelfHostServer(config)) { server.OpenAsync().Wait(); Console.WriteLine("Listening on server " + baseAddress + ". Press enter to quit."); Console.ReadLine(); } }
static void Main(string[] args) { //netsh http add urlacl url=http://+:8282/testapp/v1/ user=XYZ\ABC var selfhostConfig = new WindowsAuthSelfHostConfiguration("http://localhost:8282/testapp/v1") { //DependencyResolver = new UnityDependencyResolver(container), MaxReceivedMessageSize = int.MaxValue }; Configure(selfhostConfig); _server = new HttpSelfHostServer(selfhostConfig); _server.OpenAsync().Wait(); Console.WriteLine("Server started..."); Console.ReadKey(); }
static void Main(string[] args) { var config = new HttpSelfHostConfiguration("http://localhost:8080"); config.EnableCors(); config.Routes.MapHttpRoute( "API Default", "api/{controller}/{action}/{id}", new { id = RouteParameter.Optional }); using (HttpSelfHostServer server = new HttpSelfHostServer(config)) { server.OpenAsync().Wait(); Console.WriteLine("Press Enter to quit."); Console.ReadLine(); } }
public WebAPIService() { var baseAddress = ConfigurationManager.AppSettings["ServiceSelfHostAddress"]; var selfHostConfig = new HttpSelfHostConfiguration(baseAddress); selfHostConfig.Routes.MapHttpRoute ( name: "AkkaClusterAPI", //routeTemplate: "api/{controller}/{id}", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); CreateEventLog(baseAddress); selfHostServer = new HttpSelfHostServer(selfHostConfig); }
static void Main(string[] args) { Assembly.Load("WebApi,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null"); HttpSelfHostConfiguration configuration = new HttpSelfHostConfiguration("http://localhost:5555/selfhost"); using (HttpSelfHostServer httpServer = new HttpSelfHostServer(configuration)) { httpServer.Configuration.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); httpServer.OpenAsync(); Console.Read(); } }
static void Main(string[] args) { HttpSelfHostConfiguration configuration = new HttpSelfHostConfiguration(baseAddress); configuration.Routes.MapHttpRoute("default", "api/{controller}"); HttpSelfHostServer server = new HttpSelfHostServer(configuration); try { server.OpenAsync().Wait(); RunClient(); } finally { server.CloseAsync().Wait(); } }
public ApiServer() { const string machineName = "localhost"; HostUrl = string.Format("http://{0}:{1}/", machineName, Port); HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(HostUrl); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); _server = new HttpSelfHostServer(config); _server.OpenAsync().Wait(TimeSpan.FromSeconds(20)); }
static void Main(string[] args) { var serviceHostConfig = new HttpSelfHostConfiguration("https://127.0.0.1:34343"); //serviceHostConfig.ClientCredentialType = HttpClientCredentialType.Certificate; serviceHostConfig.ClientCredentialType = HttpClientCredentialType.None; serviceHostConfig.MessageHandlers.Add(new TestAuthorizationMetadataHandler()); var server = new HttpSelfHostServer(serviceHostConfig); server.OpenAsync().Wait(); Console.WriteLine("Press Enter to exit.."); GC.KeepAlive(server); Console.ReadLine(); }
private void StartApiHost() { var configuration = new HttpSelfHostConfiguration($"http://0.0.0.0:{_port}"); configuration.Routes.MapHttpRoute("DefaultApiWithId", "Api/{controller}/{id}", new { id = RouteParameter.Optional }, new { id = @"\d+" }); configuration.Routes.MapHttpRoute("DefaultApiWithAction", "Api/{controller}/{action}"); configuration.Routes.MapHttpRoute("DefaultApiGet", "Api/{controller}", new { action = "Get" }, new { httpMethod = new HttpMethodConstraint(HttpMethod.Get) }); configuration.Routes.MapHttpRoute("DefaultApiPost", "Api/{controller}", new { action = "Post" }, new { httpMethod = new HttpMethodConstraint(HttpMethod.Post) }); configuration.Services.Replace(typeof(IAssembliesResolver), new CustomAssemblyResolver()); configuration.DependencyResolver = ContainerBuilder.GetContainer(); configuration.MaxReceivedMessageSize = _maxMessageSize; #if DEBUG configuration.Services.Replace(typeof(IExceptionHandler), new DebuggingExceptionHandler()); #endif _httpSelfHostServer = new HttpSelfHostServer(configuration); _httpSelfHostServer.OpenAsync().Wait(); }
public void Start() { var nodeConfigString = File.ReadAllText("config.json"); var settings = new Newtonsoft.Json.JsonSerializerSettings { TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto, }; var config = Newtonsoft.Json.JsonConvert.DeserializeObject <JSONConfig>(nodeConfigString, settings); // config Syslog listener if (config.syslog.listenerEnabled) { var listener = new SyslogListener(); Action <int> startListener = listener.Start; startListener.BeginInvoke(config.syslog.listenerPort, null, null); } // config PollEngine foreach (var node in (config.nodes ?? new JSONConfigNode[0])) { var pollNode = Activator.CreateInstance(typeof(PollingEngine).Assembly.GetType(node.type), new object[] { node.name, node.groups ?? new string[0], node.settings }) as PollNode; PollingEngine.TryAdd(pollNode); } PollingEngine.StartPolling(); // config HTTP API var hostConfig = new HttpSelfHostConfiguration("http://127.0.0.1:" + config.http.listenerPort); // Remove the XML formatter hostConfig.Formatters.Remove(hostConfig.Formatters.XmlFormatter); hostConfig.Formatters.Add(new RazorFormatter()); hostConfig.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.Auto; hostConfig.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented; hostConfig.Formatters.JsonFormatter.SerializerSettings.Error += (x, y) => { return; }; hostConfig.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("type", "json", new MediaTypeHeaderValue("application/json"))); // Attribute routing. hostConfig.MapHttpAttributeRoutes(); hostConfig.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; hostConfig.Filters.Add(new ApiExceptionFilterAttribute()); httpServer = new HttpSelfHostServer(hostConfig); httpServer.OpenAsync().Wait(); }
public void Run() { var configuration = new HttpSelfHostConfiguration(Endpoint); object defaultControllerName = "Depth"; configuration.Routes.MapHttpRoute("API Default", "{action}", new { controller = defaultControllerName }); using (var server = new HttpSelfHostServer(configuration)) { server.OpenAsync().Wait(); Console.WriteLine("Server running..."); Thread.Sleep(new TimeSpan(0, 10, 0)); server.CloseAsync().Wait(); } }
public WebApiHost() { string webApiPort = ConfigurationManager.AppSettings["WebApiPort"]; _baseAddress = $"http://0.0.0.0:{webApiPort}/"; var config = new HttpSelfHostConfiguration(_baseAddress); config.MessageHandlers.Add(new DecompressionHandler()); config.MaxReceivedMessageSize = 64 * 1024 * 1024; loadControllerDlls(config.Routes); config.Routes.MapHttpRoute("API Default", "api/{controller}/{action}", new { action = RouteParameter.Optional }); _server = new HttpSelfHostServer(config); _server.OpenAsync().Wait(); _log.InfoFormat("WebApi 服务 {0} 开始工作。", _baseAddress); }
public static void Main(string[] args) { var port = "8085"; var config = new HttpSelfHostConfiguration($"http://localhost:{port}"); config.MapHttpAttributeRoutes(); using (HttpSelfHostServer server = new HttpSelfHostServer(config)) { server.OpenAsync().Wait(); Console.WriteLine($"Started host server in {port}."); while (true) { Thread.Sleep(1000); } } }
static void Main(string[] args) { var config = new HttpSelfHostConfiguration("http://localhost:8080"); config.Routes.MapHttpRoute( "ApiDefault", "api/{controller}/{id}", new { id = RouteParameter.Optional } ); var server = new HttpSelfHostServer(config); server.OpenAsync().Wait(); Console.WriteLine("Server is opened"); Console.ReadKey(); server.CloseAsync().Wait(); }
private static void Main(string[] args) { var config = new HttpSelfHostConfiguration("http://localhost:8080"); config.Routes.MapHttpRoute("Api", "Api/{controller}", new { controller = "Home" }); // Create server var server = new HttpSelfHostServer(config); // Start the server server.OpenAsync().Wait(); Console.WriteLine("WebServer Started"); Console.WriteLine("Press enter to exit"); Console.ReadLine(); }
static void Main(string[] args) { //var configuration = new HttpSelfHostConfiguration("http://localhost:8086"); var configuration = new MySelfHostConfiguration("https://localhost:8086"); WebApiConfig.Register(configuration); DtoMapperConfig.CreateMaps(); IocConfig.RegisterDependencyResolver(configuration); using (HttpSelfHostServer server = new HttpSelfHostServer(configuration)) { server.OpenAsync().Wait(); Console.WriteLine("Press Enter to terminate the server..."); Console.ReadLine(); } }
public override async Task RunAsync() { Utilities.PrintLogo(); var scriptPath = ScriptHostHelpers.GetFunctionAppRootDirectory(Environment.CurrentDirectory); var traceLevel = await ScriptHostHelpers.GetTraceLevel(scriptPath); var settings = SelfHostWebHostSettingsFactory.Create(traceLevel, scriptPath); var baseAddress = Setup(); await ReadSecrets(scriptPath, baseAddress); var config = new HttpSelfHostConfiguration(baseAddress) { IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always, TransferMode = TransferMode.Streamed, HostNameComparisonMode = HostNameComparisonMode.Exact, MaxReceivedMessageSize = 1 * 1024 * 1024 * 100 // 1 byte * 1,024 * 1,024 * 100 = 100 MB (or 104,857,600 bytes) }; if (!string.IsNullOrEmpty(CorsOrigins)) { var cors = new EnableCorsAttribute(CorsOrigins, "*", "*"); config.EnableCors(cors); } config.Formatters.Add(new JsonMediaTypeFormatter()); Environment.SetEnvironmentVariable("EDGE_NODE_PARAMS", $"--debug={NodeDebugPort}", EnvironmentVariableTarget.Process); WebApiConfig.Initialize(config, settings: settings); using (var httpServer = new HttpSelfHostServer(config)) { await httpServer.OpenAsync(); ColoredConsole.WriteLine($"Listening on {baseAddress}"); ColoredConsole.WriteLine("Hit CTRL-C to exit..."); await PostHostStartActions(config); await Task.Delay(-1); await httpServer.CloseAsync(); } }
static void Main(string[] args) { var config = new HttpSelfHostConfiguration("http://localhost:58710/"); config.Routes.MapHttpRoute("default", "api/{controller}/{id}", new { controller = "Home", id = RouteParameter.Optional }); var server = new HttpSelfHostServer(config); var task = server.OpenAsync(); task.Wait(); Console.WriteLine("Web API Server has started at http://localhost:58710"); Console.ReadLine(); }
private void StartAPI() { var config = new HttpSelfHostConfiguration("http://localhost:" + (port + 1000)); config.Routes.MapHttpRoute("API Default", "api/{controller}"); using (HttpSelfHostServer server = new HttpSelfHostServer(config)) { server.OpenAsync().Wait(); // MessageBox.Show("API RUNNING"); //This is a stupid solution but it works while (true) { Thread.Sleep(10000); } } }
public static void Main(string[] args) { HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(_baseAddress); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); var server = new HttpSelfHostServer(config); server.OpenAsync().Wait(); Console.WriteLine("Web API Self hosted on " + _baseAddress + " Hit ENTER to exit..."); Console.ReadLine(); server.CloseAsync().Wait(); }
public void Server_CanServe() { string baseAddress = "http://localhost:34543/"; var configuration = new HttpSelfHostConfiguration(baseAddress); configuration.Routes.Add("def", new HttpRoute("api/{controller}")); var server = new HttpSelfHostServer(configuration); server.OpenAsync().Wait(); var client = new HttpClient(); var result = client.GetAsync(baseAddress + "api/test").Result; Console.WriteLine(result.Content.ReadAsStringAsync().Result); result.EnsureSuccessStatusCode(); server.CloseAsync().Wait(); }
/// <summary> /// http://www.asp.net/web-api/overview/hosting-aspnet-web-api/self-host-a-web-api /// </summary> /// <param name="args"></param> static void Main(string[] args) { var config = new HttpSelfHostConfiguration("http://localhost:8080"); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); using (HttpSelfHostServer server = new HttpSelfHostServer(config)) { server.OpenAsync().Wait(); Console.WriteLine("Press Enter to quit."); Console.ReadLine(); } }
/// <summary> /// WebAPI托管(Windows自托管). /// </summary> private static void WebAPIHost() { //宿主 var config = new HttpSelfHostConfiguration(new Uri("http://localhost:55898")); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }); var host = new HttpSelfHostServer(config); host.OpenAsync().Wait(); Console.WriteLine("Press any key to exit"); Console.Read(); host.CloseAsync().Wait(); }
/// <summary> /// Stops this instance. /// </summary> public void Stop() { if (this.server != null) { try { this.server.CloseAsync().Wait(); this.config.Dispose(); this.server.Dispose(); this.server = null; } catch (Exception ex) { // Do nothing } } }
//Nuget Package: Microsoft.AspNet.WebApi.Tracing //http://blogs.msdn.com/b/roncain/archive/2012/08/16/asp-net-web-api-tracing-preview.aspx static void Main(string[] args) { HttpSelfHostConfiguration config = new HttpSelfHostConfiguration("http://localhost:8989"); config.Routes.MapHttpRoute( "DefaultHttpRoute", "api/{controller}/{id}", new { id = RouteParameter.Optional }); TraceConfig.Register(config); using (HttpSelfHostServer server = new HttpSelfHostServer(config)) { server.OpenAsync().Wait(); Console.WriteLine("Press Enter to quit."); Console.ReadLine(); } }
public ServerListProxy(ServerListParameters parameters) { Parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); var ep = parameters.ProxyServerListEndPoint; var cfg = new HttpSelfHostConfiguration( $"{parameters.Uri.Scheme}://{ep.Address}:{ep.Port}") { MessageHandlers = { new ServerListRequestHandler(parameters, out var servers), }, }; Servers = servers; _server = new HttpSelfHostServer(cfg); }
public static void Start(String port) { _url = String.Format("http://localhost:{0}/", port); var config = new HttpSelfHostConfiguration(_url); config.Routes.MapHttpAttributeRoutes(cfg => { cfg.AddRoutesFromController <BrukerController>(); cfg.AddRoutesFromController <ProsjektController>(); }); _server = new HttpSelfHostServer(config); _server.OpenAsync().Wait(); _client = new HttpClient(); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }
public static bool StartWebApiService() { try { var uri = new Uri(@"http://localhost:80/HHCloud/"); HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(uri); WebApiConfig.Config(config); var host = new HttpSelfHostServer(config); host.OpenAsync().Wait(); return(true); } catch (Exception ex) { LJH.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } return(false); }