static void Main(string[] args) { // User user = GetUser("Fly"); UserServiceClient client = new UserServiceClient(); WCFUserService.UserServiceClient newClient = new WCFUserService.UserServiceClient(); Service2Callback callback = new Service2Callback(); InstanceContext context = new InstanceContext(callback); Service2.Service2Client service2 = new Service2.Service2Client(context); service2.DoWork(); WCFUserService.User user = new WCFUserService.User(); newClient.GetUser(1,out user); Console.WriteLine(user.Name); Console.WriteLine(newClient.AddUser(new WCFUserService.User { Name = "jinjin", NickName = "yezi" })); Console.WriteLine(client.AddUser(new User { Name = "jingjing", NickName = "yezi" })); var pro = new ChannelFactory<Wcf.IService1>("service1").CreateChannel(); Console.WriteLine(pro.GetData(100)); try { newClient.Div(10, 0); } catch (FaultException<Test.WCFUserService.CalculatorError> ex) { Console.WriteLine(ex.Detail.ErrorMessage); newClient.Abort(); } client.Close(); newClient.Close(); Console.ReadKey(); }
static async Task Main(string[] args) { // The port number(5001) must match the port of the gRPC server. var channel = GrpcChannel.ForAddress("https://localhost:20987"); var client = new Service1.Service1Client(channel); var client2 = new Service2.Service2Client(channel); for (var i = 0; i < 10; i++) { try { //var reply = await client.SendAsync(new Service1Command { Name = "GrpcCli" }); //Console.WriteLine("cli1: " + reply.Message); var reply2 = await client2.SendAsync(new Service2Command { Name = "GrpcCli" }); Console.WriteLine("cli2: " + reply2.Message); await Task.Delay(1000); } catch (Exception e) { Console.WriteLine(e.Message); } } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }