Closed mgkmarco closed 1 year ago
Yes, you can do this via CallContext. I'll try to find examples later (on mobile)
Hey Marc thanks a lot for the pointer. Figured it out with something along the lines of:
public TestService(IGreeterService greeterClient, ILoggerFactory loggerFactory)
{
_greeterClient = greeterClient;
_logger = loggerFactory.CreateLogger<TestService>();
}
public async Task Unary()
{
var callContext = new CallContext(flags: CallContextFlags.CaptureMetadata);
var call = await _greeterClient.SayHelloAsync
(
new HelloRequest { Name = "GreeterClient" }, callContext
);
var headers = await callContext.ResponseHeadersAsync();
foreach(var header in headers)
{
Console.WriteLine($"Key: {header.Key} - Value: {header.Value}");
}
}
Thanks
Yup: exactly that!
Hi there, Is it possible to access metadata like headers and/or trailers from a client, other than specifying return values like
AsyncUnaryCall<T>
in the service interface?Thanks