Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protobuf-net.Grpc.AspNetCore.Reflection not worked with Grpc.AspNetCore.Server.Reflection #308

Open
LeonxPRO opened this issue Sep 11, 2023 · 4 comments

Comments

@LeonxPRO
Copy link

LeonxPRO commented Sep 11, 2023

Hi!
C# NET7 Asp.Net.Core project
I try to use both, Grpc.AspNetCore.Server.Reflection for proto-file based gRpc service GreeterGrpcProtoService and protobuf-net.Grpc.AspNetCore.Reflection for gRpc code-first service GreeterGrpcCodeFirstService simultaneously in one Asp Net Core web server.
On testing i expected discovering of both services, but see only one one GreeterGrpcProtoService discovery - 'GreeterProto/SayHello', provided by Grpc.AspNetCore.Server.Reflection. If i test this Reflection packages separated - they individually work fine.

Tested by Postman and grpCui
Code:

builder.Services.AddGrpc();
builder.Services.AddCodeFirstGrpc();
builder.Services.AddCodeFirstGrpcReflection();
builder.Services.AddGrpcReflection();
...
app.MapGrpcService<GreeterGrpcCodeFirstService>();
app.MapGrpcService<GreeterGrpcProtoService>()
app.MapCodeFirstGrpcReflectionService();
app.MapGrpcReflectionService();

After launch i see in command line text:

info: ProtoBuf.Grpc.Server.ServicesExtensions.CodeFirstServiceMethodProvider[0]
      RPC services being provided by ServiceGrpcHost.Services.GreeterGrpcCodeFirstService: 1
info: ProtoBuf.Grpc.Server.ServicesExtensions.CodeFirstServiceMethodProvider[0]
      RPC services being provided by ProtoBuf.Grpc.Reflection.ReflectionService: 1

i expected discovery both:
GreeterGrpcCodeFirstService\SayHello
GreeterProto\SayHello

actual discovered:
GreeterProto\SayHello

@zyltntking
Copy link

zyltntking commented Sep 12, 2023

same problem

and when i do this

if (app.Environment.IsDevelopment())
{
    //app.MapGrpcReflectionService();
    app.MapCodeFirstGrpcReflectionService();
}

then code first service can be discovered

@fastfend
Copy link

Can also confirm

@AYColumbia
Copy link

AYColumbia commented Oct 17, 2023

Same here. Been struggling with this for the past couple days until I finally found this post. I hope it can be fixed or a workaround found. I only see the services when defined in a .proto file and NONE of the services otherwise. both grpcurl and milkman only show the .proto services.

The client works and can create the service, call the method and get data back.

Interface decorated as below.

namespace GrpcGreeter.Interfaces
{
    [Service]
    public interface ITestService
    {
        [Operation]
        TestContract GetTestData();
    }
}

Implementation class.

namespace GrpcGreeter.Services
{
    public class TestService : ITestService
    {
        public TestContract GetTestData()
        {
            TestContract contract = new()
            {
                Id = 99,
                Name = DateTime.Now.ToString()
            };
            return contract;
        }
    }
}

Configured in Program.cs as

...
builder.Services.AddGrpc();
builder.Services.AddCodeFirstGrpc();
builder.Services.AddCodeFirstGrpcReflection();
builder.Services.AddGrpcReflection();

var app = builder.Build();

// Configure the HTTP request pipeline.
app.MapGrpcService<GreeterService>();
app.MapGrpcService<TestService>();
app.MapCodeFirstGrpcReflectionService();
app.MapGrpcReflectionService();
...

My service is running as a Windows service btw. Sample output from my console client:
GetTestData: {"Id":99,"Name":"10/17/2023 6:09:48 PM"}

[UPDATE] one correction, querying the service actually returns two entries but not what I expect, i.e., greet.Greeter and my test service. The items below is what's returned by grpcurl for example:
greet.Greeter
grpc.reflection.v1alpha.ServerReflection

@matthew-chen-sh
Copy link

also running into this problem using the below code. I was following this guide: https://martinbjorkstrom.com/posts/2020-07-08-grpc-reflection-in-net

services.AddCodeFirstGrpc();
services.AddCodeFirstGrpcReflection();

and then

app.UseEndpoints(eb => 
{
    eb.MapCodeFirstGrpcReflectionService();
});

however, I am curious because of what @zyltntking said that it could be due to a conflict in having both these lines:

    app.MapGrpcReflectionService();
    app.MapCodeFirstGrpcReflectionService();

I'm not going to be able to easily verify this as I'm relying on some internal packages that calls MapGrpcReflectionService

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants