//IPC进程内部调用发送header 整体设置 不需要每次调用都设置 var credentials = CallCredentials.FromInterceptor((context, metadata) => { if (!string.IsNullOrEmpty(_token)) { metadata.Add("Authorization", $"Bearer {_token}"); } return Task.CompletedTask; }); var channel = new ColaGrpcHelper(new ColaWindowsGrpc()).CreateChannel("https://localhost:5005",config,null,credentials); var invoker = channel.Intercept(new ClientGrpcInterceptor(builder.Services.BuildServiceProvider().GetService<IColaLogs>()!, config)); var client = new Greeter.GreeterClient(invoker);
//IPC进程内部每次调用发送header var headers = new Metadata(); headers.Add("customHeader","odin-custom-header"); var helloReply = client.SayHelloAsync(new HelloRequest { Name = "odin-sam" },headers); var resultOnce = await helloReply; Console.WriteLine(resultOnce.Message);