grpc / grpc-dotnet

gRPC for .NET
Apache License 2.0
4.18k stars 769 forks source link

Grpc client with host and port information #2247

Open ragavendra opened 1 year ago

ragavendra commented 1 year ago

hi,

This question has already been asked here

Does the Grpc client have additional methods or properties to get the server name, port number of the server. Like, I can see one method WithHost in namespace Grpc.Core . Also, this is in C# and might be needed in other languages too.

I know the GrpcChannel type has it like channel.Target in the below snippet to get that information.

var channel = GrpcChannel.ForAddress("http://localhost:1357");

var appCli = new App.AppClient(channel);

I need something like appCli.Target or similar to get that info.

PS - During debugging I could get that info from (Grpc.Net.Client.Internal.HttpClientCallInvoker) appCli.Configuration.undecoratedCallInvoker, however I could not use it in code as HttpClientCallInvoker is internal or Configuration method was not accessible.

The reason why I am asking is, say if I connect to n servers, then I need to maintain a key value for each client connection. With this feature or enhancement, I might not need to.

Apologies if this question is already answered!

JamesNK commented 1 year ago

No, that data doesn't isn't available from GrpcChannel. I suggest you store the channel in a type that has the extra metadata you need so they can be passed around together.

ragavendra commented 1 year ago

Sure, thanks for the update. I am using a variable for now to be shared across various methods but might use a property as well if in case I have to share it across different pages or similar.