// [Test] // Integration Test
        public async Task Can_call_external_secure_service_using_remote_certificate()
        {
            try
            {
                // File.WriteAllBytes("grpc.crt", "https://todoworld.servicestack.net/grpc.crt".GetBytesFromUrl());
                // var cert = new X509Certificate2("grpc.crt");
                var cert = new X509Certificate2("https://todoworld.servicestack.net/grpc.crt".GetBytesFromUrl());

                var client = new GrpcServiceClient("https://todoworld.servicestack.net:50051",
                                                   cert, GrpcUtils.AllowSelfSignedCertificatesFrom("todoworld.servicestack.net"));

                var response = await client.GetAsync(new Hello { Name = "gRPC SSL C# 50051" });

                response.Result.Print();

                client = new GrpcServiceClient("https://todoworld.servicestack.net:5051",
                                               cert, GrpcUtils.AllowSelfSignedCertificatesFrom("todoworld.servicestack.net"));

                response = await client.GetAsync(new Hello { Name = "gRPC SSL C# 5051" });

                response.Result.Print();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemplo n.º 2
0
        [Test] // Requires Host project running on https://localhost:5001 (default)
        public async Task Can_call_Hello_Service_WebHost()
        {
            var client = new GrpcServiceClient("https://localhost:5001");

            var response = await client.GetAsync(new Hello { Name = "World" });

            Assert.That(response.Result, Is.EqualTo("Hello, World!"));
        }
Exemplo n.º 3
0
        public async Task Can_GET_Hello_TodoWorld_Insecure()
        {
            var client = new GrpcServiceClient("http://todoworld.servicestack.net:5054");

            var response = await client.GetAsync(new Hello { Name = "World" });

            Assert.That(response.Result, Is.EqualTo("Hello, World!"));
        }
Exemplo n.º 4
0
        public static async Task Run(GrpcServiceClient client)
        {
            await client.PostAsync(new ResetTodos());

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

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

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

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

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

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

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

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

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

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

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

            $"todos: {all.Results?.Count ?? 0}".Print();
        }
        // [Test] // Integration Test
        public async Task Can_call_external_plaintext_service()
        {
            GrpcClientFactory.AllowUnencryptedHttp2 = true;
            var client   = new GrpcServiceClient("http://todoworld.servicestack.net:50054");
            var response = await client.GetAsync(new Hello { Name = "gRPC Text C# 50054" });

            response.Result.Print();

            client   = new GrpcServiceClient("http://todoworld.servicestack.net:5054");
            response = await client.GetAsync(new Hello { Name = "gRPC Text C# 5054" });

            response.Result.Print();
        }
Exemplo n.º 6
0
        [Test] // Requires Host project running on https://localhost:5001 (HTTP2 SSL)
        public async Task Can_GET_Hello_WebHost_Secure()
        {
            var client = new GrpcServiceClient(GrpcChannel.ForAddress("https://localhost:5001", new GrpcChannelOptions
            {
                HttpClient = new HttpClient(new HttpClientHandler()
                                            .AddPemCertificateFromFile("../../../../clients/certs/dev.crt")
                                            .AllowSelfSignedCertificatesFrom("localhost")),
            }));

            var response = await client.GetAsync(new Hello { Name = "World" });

            Assert.That(response.Result, Is.EqualTo("Hello, World!"));
        }
Exemplo n.º 7
0
        public async Task Can_GET_Hello_TodoWorld_Secure_grpc()
        {
            var client = new GrpcServiceClient(GrpcChannel.ForAddress("https://todoworld.servicestack.net:50052", new GrpcChannelOptions
            {
                HttpClient = new HttpClient(new HttpClientHandler()
                                            .AddPemCertificateFromFile("../../../../clients/certs/prod.crt")
                                            .AllowSelfSignedCertificatesFrom("todoworld.servicestack.net")),
            }));

            var response = await client.GetAsync(new Hello { Name = "World" });

            Assert.That(response.Result, Is.EqualTo("Hello, World!"));
        }