Example #1
0
        public JsonResult Save(int?Id, String Title, String Content, int AuthorId)
        {
            using (var _client = new BookService.BookServiceClient())
            {
                Models.Result result;

                if (Id == null)
                {
                    result = _client.saveBook(new Models.Book()
                    {
                        Author = new Models.Author()
                        {
                            Id = AuthorId
                        }, Title = Title, Content = Content
                    });
                }
                else
                {
                    result = _client.updateBook(new Models.Book()
                    {
                        Author = new Models.Author()
                        {
                            Id = AuthorId
                        }, Title = Title, Content = Content, Id = Id ?? 0
                    });
                }

                return(Json(new { result = result }, JsonRequestBehavior.AllowGet));
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
            var request = new SendRequest();

            request.Content       = new Any();
            request.Content.Value = Google.Protobuf.ByteString.CopyFromUtf8("{ \"Name\": \"Fabio\",  \"Surname\": \"Cozzolino\" }");
            // The port number(5001) must match the port of the gRPC server.
            var channel = GrpcChannel.ForAddress("http://localhost:5000");
            var client  = new BookService.BookServiceClient(channel);

            try
            {
                var reply = client.Send(request);
                Console.WriteLine("Greeting: " + reply.Content);
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                var exc = ex;
                while (exc != null)
                {
                    Console.WriteLine(exc.ToString());
                    exc = exc.InnerException;
                }
            }
        }
Example #3
0
        private static void Main(string[] args)
        {
            var channel             = new Channel(ServerAddress, ChannelCredentials.Insecure);
            var healthCheckClient   = new Health.HealthClient(channel);
            var healthCheckResponse = healthCheckClient.Check(new HealthCheckRequest {
                Service = ServiceName
            });

            Console.WriteLine($"Service: '{ServiceName}' has a health status: {healthCheckResponse.Status.ToString()}");
            try
            {
                healthCheckClient.Check(new HealthCheckRequest {
                    Service = "Bad Name"
                });
            }
            catch (RpcException ex)
            {
                Console.WriteLine($"Service: 'Bad Name' has a health status: {ex.Status.StatusCode.ToString()}");
            }

            var bookClient = new BookService.BookServiceClient(channel);
            var book       = bookClient.GetBookById(new GetBookByIdRequest {
                Id = 1
            });

            Console.WriteLine($"Retrieved book: {book.Name}");

            channel.ShutdownAsync().GetAwaiter().GetResult();

            Console.WriteLine("Press key to shut down ... .. .");
            Console.ReadKey();
        }
Example #4
0
        public JsonResult GetBooks(int offset, int limit)
        {
            using (var _client = new BookService.BookServiceClient())
            {
                var books = _client.GetAllBooks();

                return(Json(new { books = books }, JsonRequestBehavior.AllowGet));
            }
        }
Example #5
0
        public JsonResult Delete(int Id)
        {
            using (var _client = new BookService.BookServiceClient())
            {
                _client.deleteBook(new Models.Book()
                {
                    Id = Id
                });

                return(Json(new { }, JsonRequestBehavior.AllowGet));
            }
        }
Example #6
0
        static async Task Main(string[] args)
        {
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
            AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2Support", true);

            var channel = GrpcChannel.ForAddress("https://localhost:32794");
            var client  = new BookService.BookServiceClient(channel);

            using var call = client.GetAllBooks(new AllBooksRequest()
            {
                ItemsPerPage = 1
            });
            while (await call.ResponseStream.MoveNext())
            {
                Console.Write(Environment.NewLine);
                Console.Write(call.ResponseStream.Current.Books);
            }

            Console.ReadKey();
        }
Example #7
0
        public GrpcApiClient(string apiUrl)
        {
            var channel = Grpc.Net.Client.GrpcChannel.ForAddress(apiUrl);

            _client = new BookService.BookServiceClient(channel);
        }