1.8 KiB
gRPC C# Server Reflection
This document shows how to use gRPC Server Reflection in gRPC C#. Please see C++ Server Reflection Tutorial for general information and more examples how to use server reflection.
Enable server reflection in C# servers
C# Server Reflection is an add-on library. To use it, first install the Grpc.Reflection Nuget package into your project.
Note that with C# you need to manually register the service descriptors with the reflection service implementation when creating a server (this isn't necessary with e.g. C++ or Java)
// the reflection service will be aware of "Greeter" and "ServerReflection" services.
var reflectionServiceImpl = new ReflectionServiceImpl(Greeter.Descriptor, ServerReflection.Descriptor);
server = new Server()
{
Services =
{
// the server will serve 2 services, the Greeter and the ServerReflection
ServerReflection.BindService(new GreeterImpl()),
ServerReflection.BindService(reflectionServiceImpl)
},
Ports = { { "localhost", 50051, ServerCredentials.Insecure } }
};
server.Start();
After starting the server, you can verify that the server reflection
is working properly by using the grpc_cli
command line tool:
$ grpc_cli ls localhost:50051
output:
helloworld.Greeter
grpc.reflection.v1alpha.ServerReflection
For more examples and instructions how to use the grpc_cli
tool,
please refer to the grpc_cli
documentation
and the C++ Server Reflection Tutorial.
Additional Resources
The Server Reflection Protocol provides detailed information about how the server reflection works and describes the server reflection protocol in detail.