コード例 #1
0
        public static void Main(string[] args)
        {
            //Environment.SetEnvironmentVariable("GRPC_TRACE", "all");
            Environment.SetEnvironmentVariable("GRPC_VERBOSITY", "debug");
            GrpcEnvironment.SetLogger(new ConsoleLogger());

            //https://stackoverflow.com/questions/37714558/how-to-enable-server-side-ssl-for-grpc
            var cacert     = File.ReadAllText(@"C:\Users\ABOK078\Desktop\gRPC presentation\Grpc-Demo\cert\ca.crt");
            var servercert = File.ReadAllText(@"C:\Users\ABOK078\Desktop\gRPC presentation\Grpc-Demo\cert\server.crt");
            var serverkey  = File.ReadAllText(@"C:\Users\ABOK078\Desktop\gRPC presentation\Grpc-Demo\cert\server.key");
            var keypair    = new KeyCertificatePair(servercert, serverkey);

            var credentials = new SslServerCredentials(new[] { keypair }, cacert, true);

            Server server = new Server
            {
                Services = { MarketData.BindService(new RandomMarketDataService()) },
                //Ports = { new ServerPort("0.0.0.0", Port, ServerCredentials.Insecure) }
                Ports = { new ServerPort("0.0.0.0", Port, credentials) }
            };

            server.Start();

            Console.WriteLine("MarketData server listening on port " + Port);
            Console.WriteLine("Press any key to stop the server...");
            Console.ReadKey();

            server.ShutdownAsync().Wait();
        }