static void Main(string[] args) { var implementer = new ifns_service_interface.IFDNSServer(); implementer.ReadConfiguration(); var wcfinterface = new ServiceHost(implementer, new Uri("http://localhost:8000")); wcfinterface.AddServiceEndpoint(typeof(ifns_service_interface.IFDNSServerInterface), new BasicHttpBinding(), "ifns_client_service"); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; wcfinterface.Description.Behaviors.Add(smb); wcfinterface.Open(); implementer.RefreshRemoteHosts(); Console.ReadLine(); wcfinterface.Close(); }
protected override void OnStart(string[] args) { ServiceStatus serviceStatus = new ServiceStatus(); serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING; serviceStatus.dwWaitHint = 100000; SetServiceStatus(this.ServiceHandle, ref serviceStatus); eventLog.WriteEntry("Starting..."); try { implementer = new ifns_service_interface.IFDNSServer(); implementer.ReadConfiguration(); wcfinterface = new ServiceHost(implementer, new Uri("http://localhost:8000")); wcfinterface.AddServiceEndpoint(typeof(ifns_service_interface.IFDNSServerInterface), new BasicHttpBinding(), "ifns_client_service"); ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; wcfinterface.Description.Behaviors.Add(smb); wcfinterface.Open(); eventLog.WriteEntry("Server launched"); timer = new System.Timers.Timer(); timer.Interval = 60000 * 20; // 20 min timer.Elapsed += new System.Timers.ElapsedEventHandler(this.OnTimer); timer.Start(); // trigger initial sync OnTimer(null, null); serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING; SetServiceStatus(this.ServiceHandle, ref serviceStatus); } catch (Exception e) { System.Diagnostics.Debug.Print("ifns-client-service: " + e.ToString()); eventLog.WriteEntry("Error: " + e.ToString()); } }