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_secure_service_using_remote_certificate() { try { // File.WriteAllBytes("grpc.crt", "https://todoworld.servicestack.net/grpc.crt".GetBytesFromUrl()); // var cert = new X509Certificate2("grpc.crt"); var client = new GrpcServiceClient("https://todoworld.servicestack.net:50051", new X509Certificate2("https://todoworld.servicestack.net/grpc.crt".GetBytesFromUrl()), GrpcUtils.AllowSelfSignedCertificatesFrom("todoworld.servicestack.net")); var response = await client.GetAsync(new Hello { Name = "gRPC C#" }); response.Result.Print(); } catch (Exception e) { Console.WriteLine(e); throw; } }