[C#] Close / reject RPC from server side

90 views
Skip to first unread message

Joseph Vaughan

unread,
Apr 3, 2018, 5:25:18 AM4/3/18
to grpc.io
I have a few instances where I'd like my gRPC server to reject an RPC call using the newly introduced Interceptors functionality. I've read the documentation and can see that this is a desired piece of functionality (Cancelling RPCs). I can see the functionality is available within the Java API (ServerCall.java) which looks perfect for what I'd like to do (Cancel the RPC and return one of the internal gRPC status codes). The best solution I can find right now for a C# server is to raise an RpcException with a Status, however I'd like to avoid the use of exceptions for common control flow where possible.

Ideally I'm looking for the same functionality as demonstrated here: https://github.com/grpc/grpc-java/issues/779#issuecomment-130365950

Am I missing something on the C# side where I can already do this, and if not, are there plans to introduce a similar API?

Thanks,
Joseph.

Jan Tattermusch

unread,
Apr 6, 2018, 4:29:54 AM4/6/18
to grpc.io
In C# status server handlers (and also in interceptors on the serverside), you can set the resulting status without throwing an exception by setting ServerCallContext's "Status" property.

call.Status = new Status(StatusCode.WhateverYouWant, "");
// and then return from the server side handler.

Joseph Vaughan

unread,
Apr 19, 2018, 3:25:21 AM4/19/18
to grpc.io
Thanks Jan, I just got to test this out and this is exactly what I was after.
Reply all
Reply to author
Forward
0 new messages