ServiceModel.Grpc

Code-first for gRPC

View on GitHub

Server streaming operation

[OperationContract]
IAsyncEnumerable<TData> OperationName([T1 arg1, T2 arg2, ..., TN argN], [CancellationToken|CallContext context]);

[OperationContract]
Task<IAsyncEnumerable<TData>> OperationName([T1 arg1, T2 arg2, ..., TN argN], [CancellationToken|CallContext context]);

[OperationContract]
ValueTask<IAsyncEnumerable<TData>> OperationName([T1 arg1, T2 arg2, ..., TN argN], [CancellationToken|CallContext context]);

ServiceModel.Grpc framework supports external data in the response

[OperationContract]
Task<(IAsyncEnumerable<TData> Stream, T1 arg1, T2 arg2, ..., TN argN)> OperationName(...);

[OperationContract]
ValueTask<(T1 arg1, T2 arg2, ..., TN argN, IAsyncEnumerable<TData> Stream)> OperationName(...);

The gRPC protocol does not support external data in the response. The only way to pass it to a client is by using HTTP response headers. In case the operation contains external data in the response, ServiceModel.Grpc framework will automatically:

for example:

// standard gRPC server streaming call
[OperationContract]
Task<IAsyncEnumerable<int>> EnumerableRange(int start, int count);

// here values of Start and Count will be automatically passed in the binary response header
[OperationContract]
Task<(int Start, int Count, IAsyncEnumerable<int> Stream)> EnumerableRange(int start, int count);