private static async Task <Server> CreateServerAsync() { var host = "127.0.0.1"; var port = 40052; await Console.Out.WriteLineAsync($"Starting Grpc server on {host}:{port}"); ServerCredentials credentials; // HTTP connection, no auth token // credentials = ServerCredentials.Insecure; // HTTPS connection, no auth token var certificateChain = await File.ReadAllTextAsync(@"certstrap-out\MyService.crt"); var privateKey = await File.ReadAllTextAsync(@"certstrap-out\MyService.key"); credentials = new SslServerCredentials(new[] { new KeyCertificatePair(certificateChain, privateKey) }); var server = new Server { Services = { MyStackServer.BindService(new MyStackServerImpl()) }, Ports = { new ServerPort(host, port, credentials) } }; return(server); }
public Task StartAsync(CancellationToken cancellationToken) { _logger.LogInformation("Starting Grpc server on {}:{}", Host, Port); GrpcEnvironment.SetLogger(new LogLevelFilterLogger(new ConsoleLogger(), Grpc.Core.Logging.LogLevel.Debug)); _server = new Server { Services = { MyStackServer.BindService(_myStackServerImpl) }, Ports = { new ServerPort(Host, Port, ServerCredentials.Insecure) } }; _server.Start(); return(Task.CompletedTask); }