davidfowl / MultiProtocolAspNetCore

253 stars 32 forks source link

Using both gRPC and Rest on Kestrel #10

Closed aminebizid closed 4 years ago

aminebizid commented 4 years ago

Hi David, Is it possible to run a gRPC server and a swagger on the same Kestrel instance? Thank

davidfowl commented 4 years ago

Yes it is. gRPC is just HTTP/2

aminebizid commented 4 years ago

Any example please I'm trying this on my Mac => gRPC works great but Swagger stopped working

   public void ConfigureServices(IServiceCollection services)
        {
            services.AddGrpc();
            services.AddControllers();
 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            app.UseEndpoints(endpoints =>
            {

                endpoints.MapGrpcService<GreeterService>();
                endpoints.MapControllers();
            });

            app.UseSwagger(_configuration);
public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.ConfigureKestrel(options =>
                    {
                        // Setup a HTTP/2 endpoint without TLS.
                        options.ListenLocalhost(5000, o => o.Protocols = 
                            HttpProtocols.Http2);

                        options.ListenLocalhost(5001, o => o.Protocols =
                            HttpProtocols.Http1);
                    });
                    webBuilder.UseStartup<Startup>();
                })
aminebizid commented 4 years ago

It was swagger misconfig. Thanks

parveenLily commented 3 years ago

Hi, Both rest and Grpc works with kestrel configuration but this configuration does not work on Docker(grpc) . I am using docker desktop. any ideas / suggestion.