5

I've implemented a simple gRPC service in net5 similar to the GreeterService in the project template.

The service works fine when using IIS LocalHost but the client throws this exception when calling the remote server:

Grpc.Core.RpcException HResult=0x80131500 Message=Status(StatusCode="Internal", Detail="Request protocol 'HTTP/1.1' is not supported.")

I thought Grpc used HTTP/2 by default. What am I doing wrong ?

3
  • 1
    Do you have an IIS installation supporting HTTP/2, i.e. Server 2016 or Windows 10? Do you have a certificate (TLS)? Commented Feb 17, 2021 at 10:37
  • Without any code, one can only guess. Yes, gRPC works on HTTP/2. So when only HTTP/1.1 is available, it won't work. HTTP/2 requires HTTPS, so if the client (or server) don't use HTTPS, you can't use gRPC Commented Feb 17, 2021 at 10:39
  • Browsers can't use gRPC, so the gRPC-Web spec was created. This affects SPAs and Blazor WASM for example. Commented Feb 17, 2021 at 10:41

3 Answers 3

5

Thanks for the responses. After reading this article I realized I needed to add the Grpc-Web proxy to my app, as this translates an HTTP/1.1 client message to HTTP/2.

The code additions to client and server are explained in this article.

After making these changes/additions my gRPC messaging service is working fine. Importantly - I spent a lot of time trying to figure out how to reference certificates in my call options - but the messaging works fine without a certificate.

Sign up to request clarification or add additional context in comments.

Comments

4

I had the same problem and I have sold it with grpc web as a reverse proxy. first of all you should install Grpc.Net.Client.Web on your grpc service project. after that, use middleware.

app.UseGrpcWeb();

then replace your MapGrpcService with this command.

endpoints.MapGrpcService<yourgRPCService>().EnableGrpcWeb();

in ConfigureService method, add bellow commands.

var handler = new GrpcWebHandler(GrpcWebMode.GrpcWebText, new 
                  HttpClientHandler());
services.AddGrpcClient<YourService.YourServiceClient>(options =>
{
    options.Address = new Uri("http://YourServerAddress");
}).ConfigureChannel(o=> {
    o.HttpClient = new HttpClient(handler);
});            

now you should inject your grpc service client and call your method.

2 Comments

app.UseGrpcWeb is not enabling even after installing the Grpc.Net.Client.Web package in my .net core 3.1 application
@KamranShahid that's because you also need the Grpc.AspNetCore.Web package
2

@poury saved my life. This worked for me. I have to update my client's code in ConfigureService method and add code below. (Required Grpc.Net.Client.Web package)

services.AddGrpcClient<GreeterService.GreeterServiceClient>(o => { o.Address = new Uri("https://localhost:5001");})
.ConfigureChannel( o => 
{
     o.HttpHandler = new GrpcWebHandler(new HttpClientHandler());
});

Also enabled app.UseGrpcWeb() & endpoints.MapGrpcService<GreeterService>().EnableGrpcWeb(); on your Server's code.

PS: I don't know why, because my client's side is C# also, not a browser?

1 Comment

app.UseGrpcWeb is not enabling even after installing the Grpc.Net.Client.Web package in my .net core 3.1 application

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.