public ServerHost(GrpcChannelType channelType = GrpcChannelType.GrpcCore) { _server = new Server { Ports = { new ServerPort("localhost", Port, ServerCredentials.Insecure) } }; Channel = GrpcChannelFactory.CreateChannel(channelType, "localhost", Port); }
public async Task <KestrelHost> StartAsync(HttpProtocols protocols = HttpProtocols.Http2) { GrpcChannelExtensions.Http2UnencryptedSupport = true; _host = Host .CreateDefaultBuilder() .ConfigureServices(services => { services.AddGrpc(); services.AddServiceModelGrpc(); _configureServices?.Invoke(services); }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.Configure(app => { app.UseRouting(); _configureApp?.Invoke(app); if (_configureEndpoints != null) { app.UseEndpoints(_configureEndpoints); } }); webBuilder.UseKestrel(o => o.ListenLocalhost(_port, l => l.Protocols = protocols)); }) .Build(); try { await _host.StartAsync().ConfigureAwait(false); } catch { await DisposeAsync().ConfigureAwait(false); throw; } ClientFactory = new ClientFactory(_clientFactoryDefaultOptions); Channel = GrpcChannelFactory.CreateChannel(_channelType, "localhost", DefaultPort); return(this); }