1

My gRPC server is implemented in ASP.NET 7 in the following way:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddLogging(c => c.ClearProviders());
builder.Services.AddGrpc();

var app = builder.Build();
app.MapGrpcService<GreeterImpl>();

Console.WriteLine($"Server started at port 50051");
app.Run($"https://localhost:50051");

class GreeterImpl : Greeter.GreeterBase
{
  public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
  {
    Console.WriteLine($"Received message from {request.Name}: {request.Message}");
    return Task.FromResult(new HelloReply { Message = $"Hello {request.Name} from .NET server" });
  }
}

I use the NuGet package Grpc.AspNetCore. The .NET Client needs no certificate and works without any problems.

I have tried to implement a Java Client, basically in the following way:

ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", PORT)
                            // .usePlaintext()      // (1)
                           .useTransportSecurity()  // (2)
                           .build();
try {
  GreeterGrpc.GreeterBlockingStub blockingClient = GreeterGrpc.newBlockingStub(channel);

  HelloRequest request = HelloRequest.newBuilder()
                                     .setName("Java client")
                                     .setMessage("My message")
                                     .build();
  HelloReply reply = blockingClient.sayHello(request);
} 
catch(StatusRuntimeException ex) {
  e.printStackTrace();
}

When I create the ManagedChannel using usePlaintext, I get the exception: io.grpc.StatusRuntimeException: UNAVAILABLE: Network closed for unknown reason

Using useTransportSecurity results in the following exception: javax.net.ssl.SSLHandshakeException: General OpenSslEngine problem

Question 1: How do I have to implement the Java client that can connect to the .NET server?

Question 2: How must the .NET server be modified so that it supports plain text communication?

0 Answers0