我有一个 c#客户端和服务器,并在客户端中调用Grpc.Core.RpcException
函数时从Status(StatusCode=Unknown, Detail="Exception was thrown by handler.")
中收到类型为SendMessage
的类型为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
的未处理异常(由 proto 文件)。
堆栈跟踪为:
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;
}
}
方法的服务器端实现:
free