public ServiceHostStart(string[] serviceNames, IConsoleService[] consoleServices) { var runServices = Config.GetServiceConfigList().Where(c => serviceNames.Contains(c.Item.Key)).ToArray(); //var runServices = Config.GetServiceConfigList(); if (Config.IsConsoleMode) { foreach (var sc in runServices) { Log.Info(sc.Item.Key); Log.Info(string.Format("{0}: {1}", "HostTypeDeclaration", sc.Item.HostTypeDeclaration)); Log.Info(string.Format("{0}: {1}", "HostTypeFullname", sc.Item.HostTypeFullname)); Log.Info(string.Format("{0}: {1}", "HostTypeAssembly", sc.Item.HostTypeAssembly)); Log.Info(string.Format("{0}: {1}", "ContractTypeDeclaration", sc.Item.ContractTypeDeclaration)); Log.Info(string.Format("{0}: {1}", "ContractTypeFullname", sc.Item.ContractTypeFullname)); Log.Info(string.Format("{0}: {1}", "ContractTypeAssembly", sc.Item.ContractTypeAssembly)); Log.Info(string.Format("{0}: {1}", "ServiceAddressPort", sc.Item.ServiceAddressPort)); Log.Info(string.Format("{0}: {1}", "EndpointName", sc.Item.EndpointName)); Log.Info(string.Format("{0}: {1}", "AuthorizedGroups", sc.Item.AuthorizedGroups)); } sr = new ServiceRunner(runServices); // console services List<IConsoleService> consoleServiceList = new List<IConsoleService>(); consoleServiceList.AddRange(consoleServices); if (consoleServices != null && consoleServices.Any()) sr.AddConsoleServices(consoleServiceList); } }
static void Main(string[] args) { if (Config.IsConsoleMode) { foreach (var sc in Config.GetServiceConfigList()) { Console.WriteLine(sc.Item.Key); Console.WriteLine("{0}: {1}", "HostTypeDeclaration", sc.Item.HostTypeDeclaration); Console.WriteLine("{0}: {1}", "HostTypeFullname", sc.Item.HostTypeFullname); Console.WriteLine("{0}: {1}", "HostTypeAssembly", sc.Item.HostTypeAssembly); Console.WriteLine("{0}: {1}", "ContractTypeDeclaration", sc.Item.ContractTypeDeclaration); Console.WriteLine("{0}: {1}", "ContractTypeFullname", sc.Item.ContractTypeFullname); Console.WriteLine("{0}: {1}", "ContractTypeAssembly", sc.Item.ContractTypeAssembly); Console.WriteLine("{0}: {1}", "ServiceAddressPort", sc.Item.ServiceAddressPort); Console.WriteLine("{0}: {1}", "EndpointName", sc.Item.EndpointName); Console.WriteLine("{0}: {1}", "AuthorizedGroups", sc.Item.AuthorizedGroups); Console.WriteLine(""); } ServiceRunner sr = new ServiceRunner(); sr.Start(args); Console.WriteLine("WcfServiceHost started... Hit enter to stop..."); //Console.ReadLine(); //HANDLE m_hEvent = IntPtr.Zero; //m_hEvent = CreateEvent(IntPtr.Zero, false, false, WCF_EVENT_NAME); //SetEvent(m_hEvent, (int)EventFlags.RESET); //WaitForSingleObject(m_hEvent, System.Threading.Timeout.Infinite); Semaphore m_Read = new Semaphore(0, 1, WCF_SEM_NAME);//没有数据可读; m_Read.WaitOne(); sr.Stop(); //CloseHandle(m_hEvent); //Console.ReadLine(); } else { //Run it as a service ServiceBase[] servicesToRun; try { servicesToRun = new ServiceBase[] { new WcfService() }; ServiceBase.Run(servicesToRun); } catch (Exception e) { //do your exception handling thing e.ProcessUnhandledException("WcfServiceHost"); } } }
static void Main(string[] args) { if (Config.IsConsoleMode) { foreach (var sc in Config.GetServiceConfigList()) { Console.WriteLine(sc.Item.Key); Console.WriteLine("{0}: {1}", "HostTypeDeclaration", sc.Item.HostTypeDeclaration); Console.WriteLine("{0}: {1}", "HostTypeFullname", sc.Item.HostTypeFullname); Console.WriteLine("{0}: {1}", "HostTypeAssembly", sc.Item.HostTypeAssembly); Console.WriteLine("{0}: {1}", "ContractTypeDeclaration", sc.Item.ContractTypeDeclaration); Console.WriteLine("{0}: {1}", "ContractTypeFullname", sc.Item.ContractTypeFullname); Console.WriteLine("{0}: {1}", "ContractTypeAssembly", sc.Item.ContractTypeAssembly); Console.WriteLine("{0}: {1}", "ServiceAddressPort", sc.Item.ServiceAddressPort); Console.WriteLine("{0}: {1}", "EndpointName", sc.Item.EndpointName); Console.WriteLine("{0}: {1}", "AuthorizedGroups", sc.Item.AuthorizedGroups); Console.WriteLine(""); } ServiceRunner sr = new ServiceRunner(); sr.Start(args); Console.WriteLine("WcfServiceHost started... Hit enter to stop..."); Console.ReadLine(); sr.Stop(); } else { //Run it as a service ServiceBase[] servicesToRun; try { servicesToRun = new ServiceBase[] { new WcfService() }; ServiceBase.Run(servicesToRun); } catch (Exception e) { //do your exception handling thing e.ProcessUnhandledException("WcfServiceHost"); } } }
static void Main(string[] args) { log4net.Config.XmlConfigurator.Configure(); if (WcfConfigManager.IsConsoleMode) { foreach (var sc in WcfConfigManager.GetServiceConfigList()) { Console.WriteLine("Key:{0}\n地址:{1}\n终结点:{2}\n流量配置:{3}\n网络参数配置:{4}\n实例模式:{5}\n\n", sc.Item.Key, sc.AddressPort.AddressPort, sc.Item.EndpointName, sc.Throttle.Name, sc.NetParameter.Name, sc.Item.InstanceContextMode); } ServiceRunner sr = new ServiceRunner(); sr.Start(args); Console.WriteLine("WcfServiceHost started... Hit enter to stop..."); Console.ReadLine(); sr.Stop(); } else { //Run it as a service ServiceBase[] servicesToRun; try { servicesToRun = new ServiceBase[] { new WcfService() }; ServiceBase.Run(servicesToRun); } catch (Exception e) { //do your exception handling thing e.ProcessUnhandledException("WcfServiceHost"); } } }
public WcfService() { InitializeComponent(); serviceRunner = new ServiceRunner(); }