Ejemplo n.º 1
0
        static async Task Main(string[] args)
        {
            var channel       = GrpcChannel.ForAddress("https://localhost:5001");
            var greeterClient = new Greeter.GreeterClient(channel);

            var request = new HelloRequest()
            {
                Name = "Marcin"
            };
            HelloReply reply = await greeterClient.SayHelloAsync(request);

            Console.WriteLine(reply);

            Console.WriteLine();
            var customerClient = new Customer.CustomerClient(channel);

            using AsyncServerStreamingCall <CustomerModel> custommers = customerClient.GetNewCustomers(new Unit());
            while (await custommers.ResponseStream.MoveNext())
            {
                CustomerModel currentCustomer = custommers.ResponseStream.Current;
                Console.WriteLine(currentCustomer);
            }

            _ = Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //1、建立连接
            //GrpcChannel grpcChannel = GrpcChannel.ForAddress("https://localhost:5002");

            //// 2、客户端创建
            //GreeterClient greeterClient = new Greeter.GreeterClient(grpcChannel);

            ////// 3、开始调用
            //HelloReply helloReply = greeterClient.SayHello(new HelloRequest()
            //{
            //    Name = "grpc客户端"
            //});

            //// 3、开始调用
            //GetUserListResp resp = greeterClient.GetUserList(new GetUserListReq()
            //{
            //    Name = "GetUserList"
            //});

            //// 4、打印
            //Console.WriteLine($"返回值打印:1:{helloReply.Message};2:{resp.UserListInfo}");

            //grpcChannel.Dispose();


            using (GrpcChannel grpcChannel = GrpcChannel.ForAddress("https://localhost:5002"))
            {
                // 2、客户端创建
                GreeterClient greeterClient = new Greeter.GreeterClient(grpcChannel);

                //// 3、开始调用
                HelloReply helloReply = greeterClient.SayHello(new HelloRequest()
                {
                    Name = "grpc客户端"
                });

                // 3、开始调用
                GetUserListResp resp = greeterClient.GetUserList(new GetUserListReq()
                {
                    Name = "GetUserList"
                });

                // 4、打印
                Console.WriteLine($"返回值打印:1:{helloReply.Message};2:{resp.UserListInfo}");
            }
        }