Created
October 4, 2009 22:04
-
-
Save dvhthomas/201658 to your computer and use it in GitHub Desktop.
Starting a service in a console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class Program | |
{ | |
private static void Main(string[] args) | |
{ | |
ILogFactory factory = new NLogFactory(); | |
Log.InitializeLogFactory(factory); | |
ContainerBootstrapper.BootstrapStructureMap(); | |
if (Environment.CommandLine.ToLower().Contains("-console")) | |
{ | |
Console.WriteLine("Starting service in console mode..."); | |
using (var hostService = new GeneratorHost()) | |
{ | |
hostService.StartMeUp(); | |
Console.WriteLine("{0} is running with the following WCF endpoints..." + Environment.NewLine, | |
hostService.Host.Description.ServiceType.Name); | |
Console.WriteLine("Endpoints"); | |
Console.WriteLine("*********"); | |
foreach (var se in hostService.Host.Description.Endpoints) | |
{ | |
Console.WriteLine("Endpoint:"); | |
Console.WriteLine("name: {0}", se.Name); | |
Console.WriteLine("address: {0}", se.Address); | |
Console.WriteLine("binding: {0}", se.Binding.Name); | |
Console.WriteLine("contract: {0}\n", se.Contract.Name); | |
} | |
Console.WriteLine("Service started. Press 'Enter' to Exit"); | |
Console.ReadLine(); | |
hostService.ShutMeDown(); | |
} | |
} | |
else | |
{ | |
var servicesToRun = new ServiceBase[] {new GeneratorHost()}; | |
ServiceBase.Run(servicesToRun); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment