0

I start a gRPC server in a command line application using .NET framework as target. The gRPC server binds my own custom service and the reflection and health services. I can successfully call my own service (FoobarService) by importing the .proto file into Postman and then invoking the RPC.

However, reflection doesn't work, although I am binding the reflection service (see Program.cs below).

I tried using ktr0831/evans (evans -r -p 1337) and Postman to call the reflection service but both tools cannot find any services.

Question: Why reflection doesn't work? Am I binding/activating the reflection service correctly?


My .csproj:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net48</TargetFramework>
        <PlatformTarget>x64</PlatformTarget>
        <DebugType>portable</DebugType>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="MyCustomPackage" Version="1.0.0" />
        <PackageReference Include="Grpc.HealthCheck" Version="2.46.1" />
        <PackageReference Include="Grpc.Reflection" Version="2.48.0" />
        <PackageReference Include="Google.Protobuf" Version="3.19.4" />
        <PackageReference Include="Grpc" Version="2.44.0" />
        <PackageReference Include="Grpc.Tools" Version="2.44.0" PrivateAssets="All" />
    </ItemGroup>
    <ItemGroup>
        <Protobuf Include="myservice.proto" GrpcServices="server" />
    </ItemGroup>
</Project>

My Program.cs:

public class Program
{
    private const int Port = 1337;
    
    public static void Main(string[] args)
    {
        var server = new Server
        {
            Services =
            {
                FoobarService.BindService(new FoobarImpl()), // can be called with Postman (everything fine here)
                Health.BindService(new HealthServiceImpl()), // not working (why?)
                ServerReflection.BindService(new ReflectionServiceImpl()) // not working (why?)
            },
            Ports = {new ServerPort("localhost", Port, ServerCredentials.Insecure)}
        };
        server.Start();
        Console.WriteLine($"Server started on port {Port}.");

        // Never end. Wait for someone to kill the process.
        Thread.Sleep(-1);
    }
}

My .proto:

syntax = "proto3";

option java_multiple_files = true;

package org.acme.foobar;

service Foobar {
    rpc Read (ReadRequest) returns (ReadResonse) {}
}

message ReadRequest {
    string message = 1;
}

message ReadResonse {
    string response = 1;
}

Unfortunately, the most code examples I find in the internet are based on ASP.NET. Due to the limitations of a dependency I use, I cannot use ASP.NET and I need to run a gRPC server in a .NET framework application.

Marteng
  • 1,179
  • 13
  • 31

0 Answers0