Ejemplo n.º 1
0
        private static GrpcServices.GrpcServicesClient GetClient(Action <GrpcClientConfig> init = null)
        {
            GrpcClientFactory.AllowUnencryptedHttp2 = true;
            GrpcServiceStack.ParseResponseStatus    = bytes => ResponseStatus.Parser.ParseFrom(bytes);

            var config = new GrpcClientConfig();

            init?.Invoke(config);
            var client = new GrpcServices.GrpcServicesClient(
                GrpcServiceStack.Client("http://localhost:20000", config));

            return(client);
        }
        public static GrpcServices.GrpcServicesClient GetClient(Action <GrpcClientConfig> init = null)
        {
            GrpcClientFactory.AllowUnencryptedHttp2 = true;
            GrpcServiceStack.ParseResponseStatus    = bytes => ResponseStatus.Parser.ParseFrom(bytes);

            var config = new GrpcClientConfig();

            init?.Invoke(config);
            var client = new GrpcServices.GrpcServicesClient(
                GrpcServiceStack.Client(TestsConfig.BaseUri, config));

            return(client);
        }
Ejemplo n.º 3
0
        public static async Task <T> Exec <T>(this GrpcServices.GrpcServicesClient client, Func <GrpcServices.GrpcServicesClient, AsyncUnaryCall <T> > fn)
        {
            var call = fn(client);

            try
            {
                return(await call);
            }
            catch (RpcException e)
            {
                throw new WebServiceException(call.GetStatus(), await call.ResponseHeadersAsync, e);
            }
        }
Ejemplo n.º 4
0
        static async Task Main(string[] args)
        {
            var client = new GrpcServices.GrpcServicesClient(GrpcChannel.ForAddress("https://localhost:5002"));

            await client.PostResetTodosAsync(new ResetTodos());

            //POST /todos
            var todo = (await client.PostCreateTodoAsync(new CreateTodo {
                Title = "ServiceStack"
            })).Result;

            Console.WriteLine($"new todo Id: {todo.Id}, Title: {todo.Title}");

            //GET /todos
            var all = await client.CallGetTodosAsync(new GetTodos());

            Console.WriteLine($"todos: {all.Results?.Count ?? 0}");

            //GET /todos/1
            todo = (await client.CallGetTodoAsync(new GetTodo {
                Id = todo.Id
            })).Result;
            Console.WriteLine($"get todo Id: {todo.Id}, Title: {todo.Title}");

            //GET /todos
            all = await client.CallGetTodosAsync(new GetTodos());

            Console.WriteLine($"todos: {all.Results?.Count ?? 0}");

            //PUT /todos/1
            await client.PutUpdateTodoAsync(new UpdateTodo { Id = todo.Id, Title = "gRPC" });

            //GET /todos/1
            todo = (await client.CallGetTodoAsync(new GetTodo {
                Id = todo.Id
            })).Result;
            Console.WriteLine($"updated todo Title: {todo.Title}");

            //DELETE /todos/1
            await client.CallDeleteTodoAsync(new DeleteTodo { Id = todo.Id });

            //GET /todos
            all = await client.CallGetTodosAsync(new GetTodos());

            Console.WriteLine($"todos: {all.Results?.Count ?? 0}");
        }