ServiceModel.Grpc

Code-first for gRPC

View on GitHub

Unary operation

// blocking unary call
[OperationContract]
[TResult|void] OperationName([T1 arg1, T2 arg2, ..., TN argN], [CancellationToken|CallContext context]);

// async unary call
[OperationContract]
[Task<TResult>|Task] OperationName([T1 arg1, T2 arg2, ..., TN argN], [CancellationToken|CallContext context]);

// async unary call
[OperationContract]
[ValueTask<TResult>|ValueTask] OperationName([T1 arg1, T2 arg2, ..., TN argN], [CancellationToken|CallContext context]);

Sync over async

Sync over async allows to define an operation as async unary call and blocking unary call.

Define the contract in the following manner:

// blocking unary call is not an operation contract
TResult DoSomething(T1 arg1, T2 arg2, CancellationToken token);

// async unary call is the operation contract
[OperationContract]
Task<TResult> DoSomethingAsync(T1 arg1, T2 arg2, CancellationToken token);

Criteria:

See SyncOverAsync example.