static void Main(string[] args) { var localXmlFilePath = Environment.CurrentDirectory + @"\\XmlConfiguration\\ActorConfiguration.xml"; var localXmlFileActorConfiguration = LocalXmlFileActorConfiguration.Load(localXmlFilePath); var localXmlFileActorDirectory = new LocalXmlFileActorDirectory(localXmlFileActorConfiguration); var localActor = new RpcActor(localXmlFileActorConfiguration); var helloClient = RpcServiceProxyGenerator.CreateServiceProxy <IHelloService>(localActor, "server"); var calcClient = RpcServiceProxyGenerator.CreateServiceProxy <ICalcService>(localActor, "server"); localActor.RegisterRpcService(helloClient as RpcService); localActor.RegisterRpcService(calcClient as RpcService); localActor.Bootup(localXmlFileActorDirectory); var container = new TestContainer(); container.AddModule(new TestModule(helloClient, calcClient)); var bootstrapper = new Bootstrapper(); var engine = bootstrapper.BootWith(container); string uri = "http://localhost:3202/"; var host = new SelfHost(engine, new Uri(uri)); host.Start(); Console.WriteLine("Server is listening on [{0}].", uri); Console.WriteLine("Type something to stop ..."); Console.ReadKey(); host.Stop(); Console.WriteLine("Stopped. Goodbye!"); }
public ActionResult GetService(int id) { var host = new SelfHost { Source = "Self host Service call" }; if (id == 1) { host.Source = "Http Call"; using (var client = new SelfHostedServiceReference.SelfHostingServiceClient("BasicHttpBinding_ISelfHostingService")) { host.SayHello = client.SayHello("Selvam"); host.TodayProgram = client.TodayProgram("Selvam"); } } if (id == 2) { using (var client = new SelfHostedServiceReference.SelfHostingServiceClient("NetTcpBinding_ISelfHostingService")) { host.SayHello = client.SayHello("Subramani"); host.TodayProgram = client.TodayProgram("Subramani"); } host.Source = "Tcp Call"; } return(RedirectToAction("Index", host)); }
static void Main(string[] args) { StaticInitHelper.Run(true); ServiceHost svcHost = null; try { string URL = "http://127.0.0.1:10001/app/backend/appexample"; svcHost = SelfHost.Create(URL, typeof(WcfEntryPoint), typeof(WcfInterface)); } catch (Exception eX) { svcHost = null; Console.WriteLine("Service can not be started \n\nError Message [" + eX.Message + "]"); } if (svcHost != null) { Console.WriteLine("Running"); for (;;) { Thread.Sleep(1000); } svcHost.Close(); svcHost = null; } StaticInitHelper.Run(false); }
static void Main(string[] args) { NLogLogger.Use(); ILog log = Logger.Get <Program>(); var actor = new RpcActor(); var helloClient = new HelloClient(actor); var calcClient = new CalcClient(actor); actor.RegisterRpcService(helloClient); actor.RegisterRpcService(calcClient); actor.Bootup(); var container = new TestContainer(); container.AddModule(new TestModule(helloClient, calcClient)); var bootstrapper = new Bootstrapper(); var engine = bootstrapper.BootWith(container); string uri = "http://localhost:3202/"; var host = new SelfHost(engine, new Uri(uri)); host.Start(); Console.WriteLine("Server is listening on [{0}].", uri); Console.WriteLine("Type something to stop ..."); Console.ReadKey(); host.Stop(); Console.WriteLine("Stopped. Goodbye!"); }
public ActionResult Index(SelfHost host) { if (host == null) { host = new SelfHost(); } return(View(host)); }
public static void ConfigureIgnoreWriteExceptions(SelfHost host) { var hostType = typeof(SelfHost); var hostFields = hostType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance).ToList(); var listenerField = hostFields.First(p => p.Name == "_listener"); var listener = (HttpListener)listenerField.GetValue(host); // This doesn't seem to ignore all write exceptions, so in WriteResponse(), we still have a catch block. listener.IgnoreWriteExceptions = true; }
static void Main(string[] args) { SelfHost selfHost = new SelfHost(); selfHost.RegisterExecutingAssembly(); selfHost.Start(); Console.WriteLine("Press enter to exit"); Console.ReadLine(); }
public static void ConfigureRequestQueueLength(SelfHost host) { var hostType = typeof(SelfHost); var hostFields = hostType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance).ToList(); var listenerField = hostFields.First(p => p.Name == "_listener"); var listener = (HttpListener)listenerField.GetValue(host); // Increase the HTTP.SYS backlog queue from the default of 1000 to 65535. // To verify that this works, run 'netsh http show servicestate'. // Check "Max requests" property for your process. // https://support.microsoft.com/en-us/help/820129/http-sys-registry-settings-for-windows // http://stackoverflow.com/questions/15417062/changing-http-sys-kernel-queue-limit-when-using-net-httplistener HttpSys.SetRequestQueueLength(listener, 65535); }
/* * IMPORTANT NOTICE * 1) The console application will create a self-hosting application hence we need to * move the DLL into bin folder * Please create bin folder and copy the DLL + exe file there * * 2) Go to properties of View file and set Copy to output = Copy Always / Copy if newer * * 3) Model need to be serialized, simply put the attribute [Serializable] on each model * */ static void Main(string[] args) { try { Console.WriteLine("This application is to test sending mail from console (or background process) where there is no web request"); // Setup smtp client var smtpEmailClient = new SmtpEmailClient { SmtpClient = new SmtpClient { Host = SmtpServer, Port = SmtpPort, EnableSsl = true, UseDefaultCredentials = false, DeliveryMethod = SmtpDeliveryMethod.Network, Credentials = new NetworkCredential( FromEmailAddress, FromEmailPassword), Timeout = 20000 } }; MailClient.Default = new MailClient( smtpEmailClient, FromEmailAddress, FromEmailName ); // setup self-host SelfHost.Config(AppDomain.CurrentDomain.BaseDirectory); Console.WriteLine("1) Model"); TestModel(); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine($"Exception found: {ex.Message}\n\n{ex.StackTrace}"); Console.ReadLine(); } }
static void Main(string[] args) { var localXmlFileLocalActorPath = Environment.CurrentDirectory + @"\\XmlConfiguration\\LocalActor.xml"; var localXmlFileLocalActorConfiguration = LocalXmlFileActorConfiguration.Load(localXmlFileLocalActorPath); var localActor = new RpcActor(localXmlFileLocalActorConfiguration); var localXmlFileActorRegistryPath = Environment.CurrentDirectory + @"\\XmlConfiguration\\ActorRegistry.xml"; var localXmlFileActorRegistry = LocalXmlFileActorRegistry.Load(localXmlFileActorRegistryPath); var actorDirectory = new LocalXmlFileActorDirectory(localXmlFileActorRegistry); var localXmlFileServiceRegistryPath = Environment.CurrentDirectory + @"\\XmlConfiguration\\ServiceRegistry.xml"; var serviceRegistry = LocalXmlFileServiceRegistry.Load(localXmlFileServiceRegistryPath); var serviceDiscovery = new LocalXmlFileServiceDiscovery(serviceRegistry); var serviceRetriever = new ServiceRetriever(serviceDiscovery); var serviceResolver = new ServiceResolver(serviceRetriever); var proxyGenerator = new ServiceProxyGenerator(serviceResolver); var rpcClient = new RpcClient(localActor, actorDirectory, proxyGenerator); var helloClient = rpcClient.Resolve <IHelloService>(); var calcClient = rpcClient.Resolve <ICalcService>(); rpcClient.Bootup(); var container = new TestContainer(); container.AddModule(new TestModule(helloClient, calcClient)); var bootstrapper = new Bootstrapper(); var engine = bootstrapper.BootWith(container); string uri = "http://localhost:3202/"; var host = new SelfHost(engine, new Uri(uri)); host.Start(); Console.WriteLine("Server is listening on [{0}].", uri); Console.WriteLine("Type something to stop ..."); Console.ReadKey(); host.Stop(); rpcClient.Shutdown(); Console.WriteLine("Stopped. Goodbye!"); }
static void Main(string[] args) { NLogLogger.Use(); ILog log = Logger.Get <Program>(); var container = new ModuleContainer(); container.AddModule(new JasmineIdModule()); container.AddModule(new PeonyIdModule()); container.AddModule(new CatkinIdModule()); container.AddModule(new MongoIdModule()); container.AddModule(new SnowflakeIdModule()); var bootstrapper = new Bootstrapper(); var engine = bootstrapper.BootWith(container); string uri = "http://localhost:3202/"; var host = new SelfHost(engine, new Uri(uri)); host.Start(); log.DebugFormat("Service is listening to [{0}].", uri); while (true) { try { string text = Console.ReadLine().ToLowerInvariant(); if (text == "quit" || text == "exit") { break; } } catch (Exception ex) { Console.WriteLine(ex.Message); } } host.Stop(); log.DebugFormat("Service is stopping from [{0}].", uri); }
static void Main(string[] args) { var container = new ModuleContainer(); // http://localhost:3202/plaintext container.AddModule(new PlainModule()); var bootstrapper = new Bootstrapper(); var engine = bootstrapper.BootWith(container); var uri = @"http://localhost:3202/"; var host = new SelfHost(engine, new Uri(uri)); host.Start(); Console.WriteLine("Happer is listening - navigate to {0}.", uri); Console.WriteLine("Press enter to stop..."); Console.ReadKey(); host.Stop(); Console.WriteLine("Server is stopped."); }
static void Main(string[] args) { StaticInitHelper.Run(true); ServiceHost svcHost = null; try { string URL = "http://127.0.0.1:10123/app/backend/norma"; svcHost = SelfHost.Create(URL, typeof(WcfEntryPoint), typeof(WcfInterface)); } catch (Exception eX) { svcHost = null; Console.WriteLine("Service can not be started \n\nError Message [" + eX.Message + "]"); } if (svcHost != null) { Console.WriteLine("Running"); for (;;) { Thread.Sleep(1000); } /* * Console.WriteLine("\nPress any key to close the Service"); * for (;;) { * ConsoleKeyInfo i = Console.ReadKey (); * if (i.KeyChar != '\0') * break; * Thread.Sleep (100); * }*/ svcHost.Close(); svcHost = null; } StaticInitHelper.Run(false); }
static void Main(string[] args) { NLogLogger.Use(); var container = new ModuleContainer(); container.AddModule(new TestModule()); var bootstrapper = new Bootstrapper(); var engine = bootstrapper.BootWith(container); string uri = "http://localhost:3202/"; var host = new SelfHost(engine, new Uri(uri)); host.Start(); Console.WriteLine("Server is listening on [{0}].", uri); //AutoNavigateTo(uri); Console.ReadKey(); Console.WriteLine("Stopped. Goodbye!"); host.Stop(); Console.ReadKey(); }
public static void TuneAll(SelfHost host) { ConfigureThreadPool(); ConfigureIgnoreWriteExceptions(host); ConfigureRequestQueueLength(host); }
public async Task InvokeAsync(HttpContext context, IServicePack servicePack) { var log = new LogModels.HttpRequest.Host(); servicePack.Log.AddChild(log); var selfHost = new SelfHost(); servicePack.Authorized = false; servicePack.SelfHost = selfHost; if (context.Request.Path == "/api/Auth/Login" || context.Request.Path == "/HealthCheck" || context.Request.Path == "/api/Test/TssVersion" ) { await _next(context); return; } try { log.Authorization = "Nothing \"Authorization\" header."; string authorization = context.Request.Headers["Authorization"]; if (string.IsNullOrEmpty(authorization)) { throw new Exception(); } log.Authorization = "Error \"Authorization\" token."; if (!authorization.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase)) { throw new Exception(); } var token = authorization.Substring("Bearer ".Length).Trim(); var payload = EvoApiJwt.Extract(token); log.SessionId = payload.sessionId; var session = new Session(payload.sessionId); if (!await session.FetchAsync() || !EvoApiJwt.IsAuthenticated(token, session.Model.signingKey)) { log.Authorization = "Unauthorized."; if (context.Request.Path == "/api/HandShake") { await _next(context); return; } context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; return; } if (session.Model.banned) { context.Response.StatusCode = (int)HttpStatusCode.Forbidden; return; } log.Authorization = "Succeeded."; servicePack.Authorized = true; selfHost.sessionId = payload.sessionId; selfHost.signingKey = session.Model.signingKey; selfHost.loginDate = log.LoginDate = session.Model.loginDate; selfHost.account = log.Account = session.Model.account; selfHost.accountType = log.AccountType = session.Model.accountType; selfHost.accountAccessToken = session.Model.accountAccessToken; selfHost.matchingArea = session.Model.matchingArea; selfHost.hostType = log.HostType = session.Model.hostType; if (selfHost.hostType == evolib.HostType.Player) { log.PlayerId = session.Model.playerId; // only DedicatedServer ! if (context.Request.Path == "/api/BattlePass/PassExpSave" || context.Request.Path == "/api/Matching/EntryBattleServer" || context.Request.Path == "/api/Matching/ReportAcceptPlayer" || context.Request.Path == "/api/Matching/ReportBattlePhase" || context.Request.Path == "/api/Matching/ReportDisconnectPlayer" || context.Request.Path == "/api/Matching/DeleteLastBattle" || context.Request.Path == "/api/Matching/SearchEncryptionKey" || context.Request.Path == "/api/MatchResult/ReportMatchResult" || context.Request.Path == "/api/PlayerInformation/ReportBattleResult" || context.Request.Path == "/api/ViewMatch/ReplayInfoSave" || context.Request.Path == "/api/CareerRecord/Save" || context.Request.Path == "/api/Achievement/GetStatus" || context.Request.Path == "/api/Achievement/SaveStatus" ) { log.Authorization = "DedicatedServer's protocol."; context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return; } if (session.Model.initialLevel == 0 // PathString型は大文字小文字区別しない!のでこの書き方で良い. && context.Request.Path != "/api/PlayerInformation/SetFirstOnetime" && context.Request.Path != "/api/MasterData/Get" && context.Request.Path != "/api/HandShake" && context.Request.Path != "/api/Auth/Logout" ) { log.Authorization = "initilaLevel limit."; context.Response.StatusCode = (int)HttpStatusCode.BadRequest; return; } var player = new Player(session.Model.playerId); if (!await player.Validate(servicePack.PersonalDBShardManager) || player.Model.sessionId != payload.sessionId) { log.Authorization = "Multiple login."; context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; await session.DeleteAsync(); return; } log.PlayerName = player.Model.playerName; selfHost.playerInfo = new PlayerInfo { playerId = player.playerId, playerName = player.Model.playerName, battleRating = player.Model.battleRating, playerIconItemId = player.Model.playerIconItemId, pretendedOffline = session.Model.pretendedOffline, }; if (!session.Model.pretendedOffline) { if (session.Model.lastOnlineStamp < (DateTime.UtcNow - TimeSpan.FromMinutes(2))) { var db = servicePack.PersonalDBShardManager.PersonalDBContext(session.Model.playerId); var reco = await db.DateLogs.FindAsync(selfHost.playerInfo.playerId); if (reco == null) { reco = new DateLog(selfHost.playerInfo.playerId); await db.DateLogs.AddAsync(reco); } var onlineStamp = new OnlineStamp(selfHost.playerInfo.playerId); reco.OnlineStamp = onlineStamp.Model.date = session.Model.lastOnlineStamp = DateTime.UtcNow; await db.SaveChangesAsync(); await onlineStamp.SaveAsync(); await session.SaveAsync(); } } } else if (selfHost.hostType == evolib.HostType.BattleServer) { selfHost.battleServerInfo = new BattleServerInfo { serverId = session.Model.serverId, matchId = session.Model.matchId, }; } } catch { context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; return; } await _next(context); }
static void Main(string[] args) { StaticInitHelper.Run(true); ServiceHost svcHost = null; try { string URL = "http://127.0.0.1:10011/app/backend/nurapisample"; svcHost = SelfHost.Create(URL, typeof(WcfEntryPoint), typeof(WcfInterface)); } catch (Exception ex) { svcHost = null; Console.WriteLine("Service can not be started \n\nError Message [" + ex.Message + "]"); } try { // init the nurapi instance hNur = new NurApi(); // add the events we need hNur.InventoryStreamEvent += HNur_InventoryStreamEvent; hNur.ConnectedEvent += HNur_ConnectedEvent; hNur.DisconnectedEvent += HNur_DisconnectedEvent; // connect to the local instance(127.0.0.1:4333 is the default setting, modify this to fit your needs) hNur.ConnectSocket("127.0.0.1", 4333); } catch (Exception eX) { svcHost = null; Console.WriteLine("Could not init NurApi instance [" + eX.Message + "]"); } try { client = new Nmqtt.MqttClient("localhost", 1883, "nurapisample"); ConnectionState connectionState = client.Connect(); Console.WriteLine("MQTT connection state is [" + connectionState + "]"); } catch (Exception ex) { svcHost = null; Console.WriteLine("Could not init MQTT instance [" + ex.Message + "]"); } if (svcHost != null) { Console.WriteLine("Running"); for (;;) { Thread.Sleep(1000); } svcHost.Close(); svcHost = null; } if (svcHost != null) { StaticInitHelper.Run(false); } }
static void Main(string[] args) { var pipelines = new Pipelines(); Metric.Config //.WithAllCounters() // optional -- enable both System and App counters //.WithSystemCounters() // optional -- enable System counters //.WithAppCounters() // optional -- enable App counters //.WithReporting(r => r.WithConsoleReport(TimeSpan.FromSeconds(30))) // optional -- display to console //.WithReporting(r => r.WithCSVReports(@"C:\metrics\csv", TimeSpan.FromSeconds(30))) //.WithReporting(r => r.WithTextFileReport(@"C:\metrics\text\metrics.txt", TimeSpan.FromSeconds(30))) //.WithHttpEndpoint("http://localhost:3201/metrics/") // optional -- listen http port .WithHapper(pipelines); var container = new ModuleContainer(); // http://localhost:3202/ // http://localhost:3202/ping // http://localhost:3202/hello // http://localhost:3202/text // http://localhost:3202/time container.AddModule(new SimpleModule()); // http://localhost:3202/thread // http://localhost:3202/sleep container.AddModule(new ThreadModule()); // http://localhost:3202/plaintext container.AddModule(new PlainModule()); // http://localhost:3202/metrics // http://localhost:3202/metrics/ping // http://localhost:3202/metrics/text // http://localhost:3202/metrics/health // http://localhost:3202/metrics/json // http://localhost:3202/metrics/v1/health // http://localhost:3202/metrics/v1/json // http://localhost:3202/metrics/v2/json container.AddModule(new MetricsModule()); var bootstrapper = new Bootstrapper(); var engine = bootstrapper.BootWith(container, pipelines); // enable "Transfer-Encoding" = "chunked" instead of "Content-Length". //engine.ConfigureChunkedTransferEncoding(false); // enable "Content-Encoding" = "gzip" if "Accept-Encoding" requested. //engine.ConfigureResponseCompressionEnabled(); var uri = "http://localhost:3202/"; var host = new SelfHost(engine, new Uri(uri)); host.Start(); _log.WarnFormat("Server is listening on [{0}].", uri); while (true) { string input = Console.ReadLine().ToLowerInvariant(); if (input == "exit" || input == "quit" || input == "stop") { break; } else if (input == "restart") { _log.WarnFormat("Server is restarting."); host.Stop(); _log.WarnFormat("Server is stopped."); host.Start(); _log.WarnFormat("Server is listening on [{0}].", uri); } } host.Stop(); _log.WarnFormat("Server is stopped."); Console.ReadKey(); }
static void Main(string[] args) { SelfHost.ManageServer(); Console.WriteLine("Hello World!"); Console.ReadLine(); }