gRPC config - client interceptors (#24339)
Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com>pull/24342/head
parent
f0c0eb0b8e
commit
18f74267fd
|
@ -69,6 +69,10 @@ The following code:
|
|||
|
||||
[!code-csharp[](~/grpc/configuration/sample/Program.cs?name=snippet&highlight=3-8)]
|
||||
|
||||
Note that client interceptors aren't configured with `GrpcChannelOptions`. Instead, client interceptors are configured using the `Intercept` extension method with a channel. This extension method is in the `Grpc.Core.Interceptors` namespace.
|
||||
|
||||
[!code-csharp[](~/grpc/configuration/sample/Program2.cs?name=snippet&highlight=4)]
|
||||
|
||||
[!INCLUDE[](~/includes/gRPCazure.md)]
|
||||
|
||||
## Additional resources
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Greet;
|
||||
using Grpc.Core;
|
||||
using Grpc.Core.Interceptors;
|
||||
using Grpc.Net.Client;
|
||||
|
||||
namespace GrpcGreeterClient
|
||||
{
|
||||
class Program
|
||||
{
|
||||
#region snippet
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
var channel = GrpcChannel.ForAddress("https://localhost:5001");
|
||||
var callInvoker = channel.Intercept(new LoggingInterceptor());
|
||||
var client = new Greeter.GreeterClient(callInvoker);
|
||||
|
||||
var reply = await client.SayHelloAsync(
|
||||
new HelloRequest { Name = "GreeterClient" });
|
||||
Console.WriteLine("Greeting: " + reply.Message);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue