I checked all "Closed" issues I could find. None of them helped.
Using C# with
Nuget packages:
Grpc.Net.Client - 2.28.0
Grpc.Tools - 2.28.1
Google.Protobuf v3.11.4
Windows 10 Pro
dotnet --info)Microsoft Visual Studio Community 2019 Version 16.5.3
Building .Net Core 3.1 Console app
.NET Core SDK (reflecting any global.json):
Version: 3.1.201
Commit: b1768b4ae7
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18363
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.201\
Host (useful for support):
Version: 3.1.3
Commit: 4a9f85e9f8
.NET Core SDKs installed:
3.1.201 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Used different options to create a channel. It would be too much if I showed all options I tried with
different SocketsHttpHandler and HttpClient and GrpcChannelOptions and HttpClientHandler. The basic code which should work is below.
static string username = "un";
static string password = "pp";
static byte[] data = Encoding.ASCII.GetBytes(username + ":" + password);
static string encodedCredentials = System.Convert.ToBase64String(data);
private static GrpcChannel CreateAuthenticatedChannel(string address)
{
//using CallCredentials and below SslCredentials
var credentials = CallCredentials.FromInterceptor((context, metadata) =>
{
metadata.Add("Authorization", $"Basic {encodedCredentials}");
metadata.Add("Content-Type", "UTF8");
//metadata.Add("ContentType", "UTF8");
//metadata.Add("User-Agent", "grpc-dotnet/2.25.0.0");
//metadata.Add("grpc-accept-encoding", "identity,gzip");
//metadata.Add("Content-Type", "application/grpc");
return Task.CompletedTask;
});
// SslCredentials is used here because this channel is using TLS.
var channel = GrpcChannel.ForAddress(address, new GrpcChannelOptions
{
Credentials = ChannelCredentials.Create(new SslCredentials(), credentials)
});
return channel;
}
Then call the service
var channel = CreateAuthenticatedChannel("https://mysite");
var client = new MyDbService.MyDbServiceClient(channel);
var result = client.usersearch(new UserSearch());
Expect not to get an exception with
Status(StatusCode=Internal, Detail="Bad gRPC response. Response protocol downgraded to HTTP/1.1.")
An exception
The protocol is being downgraded to HTTP/1.1. What server are you using? Does the port support HTTP/2?
It is third-party system. They said they support protobuf which I think implies that they do support HTTP/2
Either the server or a proxy inbetween the client and the server is downgrading the connection to HTTP/1.1. That is out of Grpc.Net.Client's control.
Closing as there's no actionable work for us here. Some intermediate (or the server itself) is downgrading to HTTP/1.1 and gRPC requires HTTP/2.
Cannot accept that. I confirmed that server does support HTTP/2 and I am not sure what you mean by "intermediate" server. I cannot guarantee that every server on the way supports HTTP/2 which they should as they work as proxies. Unfortunately will not be able to use gRPC till it matures.
Most helpful comment
Cannot accept that. I confirmed that server does support HTTP/2 and I am not sure what you mean by "intermediate" server. I cannot guarantee that every server on the way supports HTTP/2 which they should as they work as proxies. Unfortunately will not be able to use gRPC till it matures.