示例#1
0
        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}");
        }