public ServiceHostGrpcServiceFactory(IExecutionContextAccessor executionContextAccessor, IOptions <ServiceProxyApplicationOptions> options, ILoggerFactory?loggerFactory)
        {
            if (executionContextAccessor == null)
            {
                throw new ArgumentNullException(nameof(executionContextAccessor));
            }

            if (options?.Value == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var baseUrl =
                options.Value.ServiceBaseUrl ??
                throw new ArgumentException($"{nameof(ServiceProxyApplicationOptions.ServiceBaseUrl)} must be specified.", nameof(options));

            var channelOptions = new GrpcChannelOptions
            {
                LoggerFactory = loggerFactory ?? NullLoggerFactory.Instance,
                // https://github.com/grpc/grpc-dotnet/issues/407#issuecomment-529705056
                ThrowOperationCanceledOnCancellation = true
            };

            _channel       = GrpcChannel.ForAddress(baseUrl, channelOptions);
            _callInvoker   = _channel.Intercept(new CaptureExecutionContextInterceptor(executionContextAccessor));
            _clientFactory = ClientFactory.Create(ServiceHostContractSerializer.CreateBinderConfiguration());
        }
예제 #2
0
        public static void Init(Action <string> errcallback, HttpClient httpclient = null)
        {
            if (m_cli == null)
            {
                GrpcChannel channel = null;

                if (httpclient != null)
                {
                    channel = GrpcChannel.ForAddress(addr, new GrpcChannelOptions()
                    {
                        HttpClient            = httpclient,
                        MaxSendMessageSize    = 30 * 1024 * 1024,
                        MaxReceiveMessageSize = 30 * 1024 * 1024
                    });
                }
                else
                {
                    channel = GrpcChannel.ForAddress(addr, new GrpcChannelOptions()
                    {
                        MaxSendMessageSize    = 30 * 1024 * 1024,
                        MaxReceiveMessageSize = 30 * 1024 * 1024
                    });
                }

                var invoker = channel.Intercept(new ExceptionInterceptor(errcallback));

                var client = new PVFServices.Pvf.PvfClient(invoker);
                client.TestConnect(new Google.Protobuf.WellKnownTypes.Empty());
                m_cli = client;
            }
        }
예제 #3
0
 private async static Task InterceptorMethod(GrpcChannel channel)
 {
     var invoker = channel.Intercept(new ClientLoggerInterceptor());
     var client  = new WeatherForecastsClient(invoker);
     var result  = await client.GetWeatherForecastsAsync(new Weather.GetWeatherForecastsRequest {
         ReturnCount = 100
     });
 }
예제 #4
0
 private CallInvoker AppendAuthHeader(GrpcChannel channel)
 {
     // Append the authorization header if present
     return(channel.Intercept((source) =>
     {
         var token = httpContextAccessor.HttpContext.Request.Headers["Authorization"];
         if (token != StringValues.Empty)
         {
             source.Add("Authorization", token);
         }
         return source;
     }));
 }
예제 #5
0
        private static async Task Main(string[] args)
        {
            GrpcChannel channel           = GrpcChannel.ForAddress("https://localhost:45679");
            var         httpsClientTicker = new Ticker.TickerClient(channel);

            GrpcChannel authChannel = GrpcChannel.ForAddress("https://localhost:56790");
            var         httpsClient = new Auth.AuthClient(authChannel);

            var interceptorHttps = channel.Intercept(new HeaderLoggerInterceptor());
            var healthChecker    = new Health.HealthClient(interceptorHttps);

            string serviceName = "Ticker";

            var result = await healthChecker.CheckAsync(new HealthCheckRequest { Service = serviceName });

            Console.WriteLine(result?.Status);

            /*  var reply = await httpsClient.LogInAsync(new LogInRequest { Username = "******", Password = "******" });
             * var replyUser = await httpsClient.LogInAsync(new LogInRequest { Username = "******", Password = "******" });
             *
             * var tokenAdmin =
             *    await Authenticate(reply.Role);
             *
             * var tokenUser = await Authenticate(replyUser.Role);
             *
             *
             * Console.WriteLine(tokenAdmin);
             * Console.WriteLine(tokenUser);
             *
             * await ClientStreaming(httpsClientTicker, 1, tokenUser);
             *
             *
             *
             * /*await UpdateTickHandling(httpsClient,
             *    new TickToAdd
             *    {
             *        InstrumentId = 1,
             *        Close = (DecimalValue)5.6234m,
             *        Open = (DecimalValue)5.6225m,
             *        High = (DecimalValue)5.6238m,
             *        Low = (DecimalValue)5.6224m,
             *        Symbol = 2
             *    });
             * await GetTicksForQuota(httpsClient, 1);*/
            //await ClientStreaming(httpsClient, 1);


            Console.WriteLine("Press any key to close app...");
            Console.ReadLine();
        }
예제 #6
0
 public static CallInvoker ForServiceStack(this GrpcChannel channel, GrpcClientConfig config = null) =>
 channel.Intercept(new ServiceStackClientInterceptor(channel, config ?? new GrpcClientConfig()));