grpc необработанное исключение StatusCode = неизвестно при вызове метода, сгенерированного из файла прото - PullRequest
0 голосов
/ 23 октября 2018

У меня есть c # клиент и сервер, и я получаю необработанное исключение типа Grpc.Core.RpcException с Status(StatusCode=Unknown, Detail="Exception was thrown by handler.") при вызове функции SendMessage в клиенте (генерируется из proto файл).

Трассировка стека:

Got response: True
RPC failed Grpc.Core.RpcException: Status(StatusCode=Unknown, Detail="Exception was thrown by handler.")
   at Grpc.Core.Internal.AsyncCall`2.UnaryCall(TRequest msg) in T:\src\github\grpc\src\csharp\Grpc.Core\Internal\AsyncCall.cs:line 75
   at Grpc.Core.DefaultCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request) in T:\src\github\grpc\src\csharp\Grpc.Core\DefaultCallInvoker.cs:line 46
   at Grpc.Core.Interceptors.InterceptingCallInvoker.<BlockingUnaryCall>b__3_0[TRequest,TResponse](TRequest req, ClientInterceptorContext`2 ctx) in T:\src\github\grpc\src\csharp\Grpc.Core\Interceptors\InterceptingCallInvoker.cs:line 51
   at Grpc.Core.ClientBase.ClientBaseConfiguration.ClientBaseConfigurationInterceptor.BlockingUnaryCall[TRequest,TResponse](TRequest request, ClientInterceptorContext`2 context, BlockingUnaryCallContinuation`2 continuation) in T:\src\github\grpc\src\csharp\Grpc.Core\ClientBase.cs:line 174
   at Grpc.Core.Interceptors.InterceptingCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request) in T:\src\github\grpc\src\csharp\Grpc.Core\Interceptors\InterceptingCallInvoker.cs:line 48
   at MessageService.MessageServiceClient.SendMessage(Message request, CallOptions options) in C:\Work\Dev\sphirra\hub-communication\message-hub\Hub-Messenger\MessageGrpc.cs:line 95
   at MessageService.MessageServiceClient.SendMessage(Message request, Metadata headers, Nullable`1 deadline, CancellationToken cancellationToken) in C:\Work\Dev\sphirra\hub-communication\message-hub\Hub-Messenger\MessageGrpc.cs:line 91
   at Hub_messenger_Client.Program.HubMessengerClient.SendMessage(String msg, Int32 receiverId) in C:\Work\Dev\sphirra\hub-communication\message-hub\Hub-messenger-Client\Program.cs:line 156

Метод sendMessage в файле proto выглядит следующим образом:

service MessageService{

rpc SendMessage(Message) returns (Empty){}
}

message Message{
    bytes msg = 1;
    int32 senderId = 2;
    int32 receiverId = 3;
}

message Empty {}

Реализация SendMessage в клиенте:

public void SendMessage(String msg, int receiverId)
            {
                try
                {
                    client.SendMessage(NewMsg(msg, ID, receiverId)); //this is where it gets stuck
                    Log("sending: ", msg);
                }
                catch (RpcException e)
                {
                    Log("RPC failed " + e);
                    throw;
                }
            }

Реализация метода на стороне сервера:

public override Task<Empty> SendMessage(Message request, ServerCallContext context)
        {
            try
            {
                Task<Empty> empty = null;
                messages.Add(request);
                return empty;
            }
            catch (RpcException e){
                Console.WriteLine("Remote procedure call failed: " + e);
                throw;
            }

        }
...