Exemple #1
0
        static void Main(string[] args)
        {
            Server server = null;

            try
            {
                string serverCertificate = File.ReadAllText("GRPCServer/ssl/server.crt");
                string serverKey         = File.ReadAllText("GRPCServer/ssl/server.key");
                string caCertificate     = File.ReadAllText("GRPCServer/ssl/ca.crt");
                SslServerCredentials serverCredentials = new SslServerCredentials(new List <KeyCertificatePair>()
                {
                    new KeyCertificatePair(serverCertificate, serverKey)
                }, caCertificate, true);

                server = new Server()
                {
                    Services = { GreetService.BindService(new GreetServiceConstruct()),
                                 SquareRootService.BindService(new SquareRootServiceConstruct()),
                                 BlogService.BindService(new BlogServiceConstruct()) },
                    Ports = { new ServerPort("localhost", _port, serverCredentials) }
                };

                server.Start();
                Console.WriteLine("The sever is listening on port: " + _port);
                Console.ReadKey();
            }
            catch (IOException e)
            {
                Console.WriteLine("The _server is failed to start " + e.Message);
            }
            finally
            {
                if (server != null)
                {
                    server.ShutdownAsync().Wait();
                }
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var serverCert        = File.ReadAllText("../../../ssl/server.crt");
            var serverKey         = File.ReadAllText("../../../ssl/server.key");
            var caCert            = File.ReadAllText("../../../ssl/ca.crt");
            var channelCredential = new SslServerCredentials(new List <KeyCertificatePair> {
                new KeyCertificatePair(serverCert, serverKey)
            }, caCert, true);
            var serviceDesc = new ReflectionServiceImpl(GreetingService.Descriptor, ServerReflection.Descriptor);

            Grpc.Core.Server server = new Grpc.Core.Server
            {
                Services = { GreetingService.BindService(new GreetingServiceImpl()),
                             PrimeNumberDecomposition.BindService(new PrimeNumberDecompositionServiceImpl()),
                             SquareRootService.BindService(new SquareRootServiceImpl()),
                             ServerReflection.BindService(serviceDesc) },
                //Ports = { new ServerPort("localhost", 5000, ServerCredentials.Insecure) }
                Ports = { new ServerPort("localhost", 5000, channelCredential) }
            };
            server.Start();
            Console.WriteLine("server started...");
            Console.ReadLine();
        }