public override Task <HelloReply> SayHelloAgain(HelloRequest request, ServerCallContext context) { // you can throw RpcException // first error message is available to the client // second idential error message is only available to the server var rpcEx = new RpcException(new Status(StatusCode.InvalidArgument, "Specify at least one accounting code"), "Specify at least one accounting code"); throw rpcEx; // ... unhandled exception somewhere later occurs. No worries our log interceptor has a try catch // instead of try catch we can set the Status directly and return the response context.Status = new Status(StatusCode.InvalidArgument, "Specify at least one accounting code"); var response = new HelloReply { Message = "Hello Again " + request.Name }; return(Task.FromResult(response)); }
public override async Task Test2(IAsyncStreamReader <HelloRequest> requestStream, IServerStreamWriter <HelloReply> responseStream, ServerCallContext context) { _responseStreams.Add(responseStream); while (requestStream.MoveNext(CancellationToken.None).Result) { var client = requestStream.Current; Console.WriteLine($" client msg :: {client.Name} "); var msg = new HelloReply { Message = $" response msg :: Hola - {client.Name} " }; foreach (var stream in _responseStreams) { stream.WriteAsync(msg).Wait(); } } }