Class GrpcReflectionService
Provides gRPC reflection functionality including service discovery, method schema retrieval, and dynamic gRPC invocation based on reflection data.
public class GrpcReflectionService
- Inheritance
-
GrpcReflectionService
- Inherited Members
Constructors
GrpcReflectionService(GrpcChannelPool, ILogger<GrpcReflectionService>, IConfiguration)
public GrpcReflectionService(GrpcChannelPool channelPool, ILogger<GrpcReflectionService> logger, IConfiguration configuration)
Parameters
channelPoolGrpcChannelPoolloggerILogger<GrpcReflectionService>configurationIConfiguration
Methods
ExecuteCallAsync(string, string, byte[], Dictionary<string, string>?, CancellationToken)
Executes a gRPC call with raw protobuf bytes (passthrough, no conversion).
public Task<GrpcCallResult> ExecuteCallAsync(string serviceName, string methodName, byte[] requestData, Dictionary<string, string>? metadata = null, CancellationToken cancellationToken = default)
Parameters
serviceNamestringThe target service name.
methodNamestringThe method to invoke.
requestDatabyte[]The raw protobuf request data as bytes.
metadataDictionary<string, string>Optional metadata headers.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<GrpcCallResult>
The result of the gRPC call with raw protobuf bytes.
ExecuteCallAsync(string, string, string, Dictionary<string, string>?, CancellationToken)
Executes a gRPC call by name, using reflection for type information.
public Task<GrpcCallResult> ExecuteCallAsync(string serviceName, string methodName, string requestJson, Dictionary<string, string>? metadata = null, CancellationToken cancellationToken = default)
Parameters
serviceNamestringThe target service name.
methodNamestringThe method to invoke.
requestJsonstringThe request payload as JSON.
metadataDictionary<string, string>Optional metadata headers.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<GrpcCallResult>
The result of the gRPC call.
GetFileDescriptorProtosAsync(string, CancellationToken)
Retrieves the raw file descriptor protos for a service.
public Task<List<ByteString>> GetFileDescriptorProtosAsync(string serviceName, CancellationToken cancellationToken = default)
Parameters
serviceNamestringThe name of the service.
cancellationTokenCancellationTokenA cancellation token.
Returns
GetMethodSchemaAsync(string, string, string?, CancellationToken)
Gets the schema for a specific method including input/output types and field definitions.
public Task<MethodSchema?> GetMethodSchemaAsync(string serviceName, string methodName, string? type = null, CancellationToken cancellationToken = default)
Parameters
serviceNamestringThe name of the service.
methodNamestringThe name of the method.
typestringOptional type name for schema resolution.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<MethodSchema>
The method schema or null if not found.
GetMethodsAsync(string, CancellationToken)
Retrieves all methods for a given service using gRPC reflection.
public Task<List<ServiceMethodInfo>> GetMethodsAsync(string serviceName, CancellationToken cancellationToken = default)
Parameters
serviceNamestringThe name of the service to query.
cancellationTokenCancellationTokenA cancellation token.
Returns
- Task<List<ServiceMethodInfo>>
A list of ServiceMethodInfo describing each method.
InvalidateAllCaches()
Invalidates all service descriptor caches.
public void InvalidateAllCaches()
InvalidateCache(string)
Invalidates the reflection descriptor cache for a specific service. Forces a reload of proto schemas on the next access.
public void InvalidateCache(string serviceName)
Parameters
serviceNamestringThe service name to invalidate.