cyanfish / grpc-dotnet-namedpipes

Named pipe transport for gRPC in C#/.NET
Apache License 2.0
190 stars 48 forks source link

Code-first support via protobuf-net.Grpc: using CallContext in servicecontracts #26

Closed rkiggen closed 3 years ago

rkiggen commented 3 years ago

Hi,

first of all thanks for the great implementation.

I've followed the steps you listed in https://github.com/cyanfish/grpc-dotnet-namedpipes/issues/18#issuecomment-763346167_ for setting up code first support via protobuf-net.grpc.

And it does work however there is a small issue, with passing in the CallContext in the method:

if I define a ServiceContract like this:

[ServiceContract]
public interface IHealthManager
{
    [OperationContract]
    Reply<bool> IsAlive(IsAliveRequest request, CallContext context = default);         
}

(The CallContext is the CallContext defined in Protobuf.Grpc) I receive an exception when calling the service.

However when I change the servicecontract to the following:

[ServiceContract]
public interface IHealthManager
{
    [OperationContract]
    Reply<bool> IsAlive(IsAliveRequest request);         
}

I can call the service without any problem.

Maybe you have a clue as to how I can fix this?

Kind regards,

Rob

cyanfish commented 3 years ago

What exception do you get?

rkiggen commented 3 years ago

Hi,

I attached the project as a zipfile, just run the TestClient if you want to see what happens. inproc.grpc.zip

The Exception I get is a AggregateException: One or more errors occurred. (Status(StatusCode="Unknown", Detail="Exception was thrown by handler.")), and the InnerException is: Grpc.Core.RpcException: Status(StatusCode="Unknown", Detail="Exception was thrown by handler.") at GrpcDotNetNamedPipes.Internal.MessageReader1.MoveNext(CancellationToken cancellationToken) at GrpcDotNetNamedPipes.Internal.MessageReader1.<>c__DisplayClass9_0.<b__0>d.MoveNext()

This is the entire stacktrace: at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at System.Threading.Tasks.Task1.get_Result() at GrpcDotNetNamedPipes.NamedPipeChannel.BlockingUnaryCall[TRequest,TResponse](Method2 method, String host, CallOptions callOptions, TRequest request) at Grpc.Core.Interceptors.InterceptingCallInvoker.<BlockingUnaryCall>b__3_0[TRequest,TResponse](TRequest req, ClientInterceptorContext2 ctx) at Grpc.Core.ClientBase.ClientBaseConfiguration.ClientBaseConfigurationInterceptor.BlockingUnaryCall[TRequest,TResponse](TRequest request, ClientInterceptorContext2 context, BlockingUnaryCallContinuation2 continuation) at Grpc.Core.Interceptors.InterceptingCallInvoker.BlockingUnaryCall[TRequest,TResponse](Method`2 method, String host, CallOptions options, TRequest request) at ProtoBuf.Grpc.Internal.Proxies.ClientBase.IHealthManager_Proxy_0.IHealthManager.IsAlive(IsAliveRequest , CallContext ) at TestClient.Program.CallHealthManager() in C:\Development\playground\inproc.grpc\source\TestClient\Program.cs:line 75

cyanfish commented 3 years ago

The issue seems to be here, in that Protobuf.Net accesses the write options and we throw a NotSupportedException. I can change it to make it a normal (unused) property rather than throwing an exception.

If you want to have it work in the meantime before I publish that fix, you can recompile GrpcDotNetNamedPipes yourself with the change.

rkiggen commented 3 years ago

Thanks for the quick reply, I can confirm that your fix works. I should have thought of this myself to debug with the source code of your project :-)

cyanfish commented 3 years ago

Great. By the way, are you able to provide your server binder code under the Apache license, in case I end up providing a package for code-first support?

rkiggen commented 3 years ago

Hi Ben,

you are free to do with that code whatever you want.

Kind regards,

Rob

On April 19, 2021 3:18:42 AM GMT+02:00, Ben Olden-Cooligan @.***> wrote:

Great. By the way, are you able to provide your server binder code under the Apache license, in case I end up providing a package for code-first support?

-- You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub: https://github.com/cyanfish/grpc-dotnet-namedpipes/issues/26#issuecomment-822106786

-- Verstuurd vanaf mijn Android apparaat met K-9 Mail. Excuseer mijn beknoptheid.

cyanfish commented 3 years ago

Thanks!