• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# gRPC C# Server Reflection
2
3This document shows how to use gRPC Server Reflection in gRPC C#.
4Please see [C++ Server Reflection Tutorial](../server_reflection_tutorial.md)
5for general information and more examples how to use server reflection.
6
7## Enable server reflection in C# servers
8
9C# Server Reflection is an add-on library.
10To use it, first install the [Grpc.Reflection](https://www.nuget.org/packages/Grpc.Reflection/)
11Nuget package into your project.
12
13Note that with C# you need to manually register the service
14descriptors with the reflection service implementation when creating a server
15(this isn't necessary with e.g. C++ or Java)
16```csharp
17// the reflection service will be aware of "Greeter" and "ServerReflection" services.
18var reflectionServiceImpl = new ReflectionServiceImpl(Greeter.Descriptor, ServerReflection.Descriptor);
19server = new Server()
20{
21    Services =
22    {
23        // the server will serve 2 services, the Greeter and the ServerReflection
24        ServerReflection.BindService(new GreeterImpl()),
25        ServerReflection.BindService(reflectionServiceImpl)
26    },
27    Ports = { { "localhost", 50051, ServerCredentials.Insecure } }
28};
29server.Start();
30```
31
32After starting the server, you can verify that the server reflection
33is working properly by using the [`grpc_cli` command line
34tool](https://github.com/grpc/grpc/blob/master/doc/command_line_tool.md):
35
36 ```sh
37  $ grpc_cli ls localhost:50051
38  ```
39
40  output:
41  ```sh
42  helloworld.Greeter
43  grpc.reflection.v1alpha.ServerReflection
44  ```
45
46  For more examples and instructions how to use the `grpc_cli` tool,
47  please refer to the [`grpc_cli` documentation](../command_line_tool.md)
48  and the [C++ Server Reflection Tutorial](../server_reflection_tutorial.md).
49
50## Additional Resources
51
52The [Server Reflection Protocol](../server-reflection.md) provides detailed
53information about how the server reflection works and describes the server reflection
54protocol in detail.
55