Invoke gRPC Service ignoring system proxy

Christian Havel 96 Reputation points
2021-03-21T10:26:41.99+00:00

Hi, I have implemented a simple gRPC service using .NET Core 3.1 that is running as a ConsoleApp.
I wrote a simple .NET Core 3.1 gRPC client, that is running as a Console app, too.
If I disable in the system configuration the option to detect the proxy my sample works fine.
If it is activated I get a error message and in WireShark I find the information, that the proxy blocks the call

How can I force the client not to use the proxy?
This is my client code:

var channel = new Channel($"127.0.0.1:2231", ChannelCredentials.Insecure);
_serviceClient = new MyService.MyServiceClient(channel);
var request = new HelloRequest {Name = "Franz"};
var reply = _serviceClient.SayHello(request);

And this is the relevant code from the gRPC service:

var credentials = ServerCredentials.Insecure;
var hostName = "127.0.0.1";
_port = new ServerPort(hostName, 2231, credentials);
_rpcServer = new Server { Services = {MyService.BindService(new MyServiceImpl())}, Ports = { _port }};
_rpcServer.Start();

How do I configure on client side to use or not to use the proxy? Or how can I explicit configure the proxy including the credentials on the client?
Thanks,
Christian

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,996 questions
0 comments No comments
{count} votes

Accepted answer
  1. Christian Havel 96 Reputation points
    2021-03-22T12:46:44.507+00:00

    Hi,

    I found the solution:

    AppContext.SetSwitch(                    "System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
    
    string Ip = "My.IP.That.Works"; 
    var channel = GrpcChannel.ForAddress($"http://{Ip}:{Port}");
    MyService.MyServiceClient client = new MyService.MyServiceClient(channel);
    
    var request = new HelloRequest {Name = "MyName"};
    var reply = client.SayHello(request);
    

    Christian

    0 comments No comments

0 additional answers

Sort by: Most helpful