I'm attempting to connect to a Go GRPC Server from a C# Client but the client channel is failing to connect to the server.
I would expect that there should be no issues in connecting to a GRPC server that is written and hosted by Go and a client written in C#.
My Go Server connection is setup thus:
lis, err := net.Listen("tcp", ":50051")
if err != nil {
log.Fatalf("Failed to listen: %v", err)
}
s := grpc.NewServer()
pb.Register**ServiceServer(s, &server{})
reflection.Register(s)
if err := s.Serve(lis); err != nil {
log.Fatalf("Failed to serve: %v", err)
}
This is fairly standard and I know that my Server is working as I am able to connect with a Go client using the supplied port:
conn, err := grpc.Dial("localhost:50051", grpc.WithInsecure(), grpc.WithBlock())
But when I attempt to connect using a C# Client using the Grpc.Net.Client
package as thus:
var channel = GrpcChannel.ForAddress(@"http://localhost:50051", new GrpcChannelOptions
{
Credentials = ChannelCredentials.Insecure
});
I get a Grpc.Core.RpcException: 'Status(StatusCode=Internal, Detail="Bad gRPC response. Response protocol downgraded to HTTP/1.1.")'
exception.
Or by using the Grpc.Core
package as thus:
var channel = new Channel("localhost:50051", ChannelCredentials.Insecure);
results in a Grpc.Core.RpcException: 'Status(StatusCode=Unavailable, Detail="failed to connect to all addresses")'
exception.
I've tried both methods with and without Http2UnencryptedSupport
set within the C# client but I've run out of ideas on why I am unable to connect.
Any suggestions on where I am going wrong would be appreciated.
Http2UnencryptedSupport
thing with setting theNet.Client
manually on ForAddress?Net.Client.DefaultRequestVersion
is HTTP1.1 by default. Maybe also try settingNet.Client.DefaultVersionPolicy
toHttpVersionPolicy.RequestVersionExact
. – CarricoAppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);
andAppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
I am able to send a recieve message from the golang server. I'm not sure what has changed since v2.29 and v2.34 but one of the changes in here has resolved this for me. – PredestinateAppContext.SetSwitch
but with unencrypted support enabled for use without credentials (not recommended for a production environment). – Predestinate