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
ContainsFileAsync(string, string, CancellationToken)
Returns true when the backend's descriptor set includes the given proto file name.
public Task<bool> ContainsFileAsync(string serviceName, string fileName, CancellationToken cancellationToken = default)
Parameters
serviceNamestringThe name of the service as registered with the gateway.
fileNamestringThe proto file name (e.g. "workmanager.proto").
cancellationTokenCancellationTokenA cancellation token.
Returns
ContainsSymbolAsync(string, string, CancellationToken)
Returns true when the backend's descriptor set defines the given fully-qualified symbol (service, message, or enum name).
public Task<bool> ContainsSymbolAsync(string serviceName, string symbol, CancellationToken cancellationToken = default)
Parameters
serviceNamestringThe name of the service as registered with the gateway.
symbolstringThe fully-qualified symbol to look up.
cancellationTokenCancellationTokenA cancellation token.
Returns
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.
GetOrderedFileDescriptorProtosAsync(string, CancellationToken)
Retrieves the file descriptor protos for a service in dependency order, including the well-known transitive dependencies (descriptor.proto, annotations.proto, http.proto) that backend reflection servers omit. Suitable for feeding into a descriptor pool in returned order.
public Task<List<ByteString>> GetOrderedFileDescriptorProtosAsync(string serviceName, CancellationToken cancellationToken = default)
Parameters
serviceNamestringThe name of the service.
cancellationTokenCancellationTokenA cancellation token.
Returns
GetServiceFullNamesAsync(string, CancellationToken)
Returns the fully-qualified names of the gRPC services exposed by a backend (e.g. "virtufin.WorkManager"), loading the reflection cache on demand.
public Task<List<string>> GetServiceFullNamesAsync(string serviceName, CancellationToken cancellationToken = default)
Parameters
serviceNamestringThe name of the service as registered with the gateway.
cancellationTokenCancellationTokenA cancellation token.
Returns
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.