public void Start(int port) { if (_host != null) { throw new Exception("Daemon already running"); } var baseAddress = new Uri("net.tcp://localhost:" + port); _host = new ServiceHost(_service, baseAddress); _host.AddServiceEndpoint(typeof(IDaemonService), WCFSettings.GetTcpBinding(), baseAddress); //_host.Description.Behaviors.Add(new System.ServiceModel.Discovery.ServiceDiscoveryBehavior()) //starts var smb = _host.Description.Behaviors.Find <ServiceMetadataBehavior>(); if (smb == null) { smb = new ServiceMetadataBehavior(); } smb.HttpGetEnabled = true; smb.HttpGetUrl = new Uri($"http://localhost:{port+2}/met"); smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; _host.Description.Behaviors.Add(smb); _host.AddServiceEndpoint(typeof(IDaemonService), new WSHttpBinding(), $"http://localhost:{port + 2}/met"); _host.Open(); }
public DaemonService(int port = 666, bool addMetadata = false) { Port = port; PointService = new PointService(); IP = IPAddressReceive.GetLocalIPAddress(); var baseAddress = new Uri("net.tcp://localhost:" + (port + 1)); var host = new ServiceHost(PointService); host.AddServiceEndpoint(typeof(IPointService), WCFSettings.GetTcpBinding(), baseAddress); var baseAddress2 = new Uri("net.pipe://localhost/" + (port + 1)); host.AddServiceEndpoint(typeof(IPointService), WCFSettings.GetNamedPipeBinding(), baseAddress2); var metadataAdress = new Uri($"http://localhost:{port + 3}/met"); var smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; smb.HttpGetUrl = new Uri($"http://localhost:{port + 3}/met"); smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15; host.Description.Behaviors.Add(smb); host.AddServiceEndpoint(typeof(IPointService), new WSHttpBinding(), $"http://localhost:{port + 3}/met"); host.Open(); Console.WriteLine($"Daemon was hosted on URI:"); Console.WriteLine($"net.tcp://{IP}:{Port}"); Console.WriteLine($"Point service hosted on addresses:"); Console.WriteLine($"net.pipe://{IP}/{Port + 1}"); Console.WriteLine($"net.tcp://{IP}:{Port + 1}"); }