static async Task Main(string[] args) { var httpClient = new HttpClient( new HttpClientHandler() { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator }); var channel = GrpcChannel.ForAddress("https://localhost:5001", new GrpcChannelOptions { HttpClient = httpClient }); var client = new CustomerService.CustomerServiceClient(channel); var request = new CustomerIdRequest() { CustId = 1 }; var reply = await client.GetCustomerByIdAsync(request); Console.WriteLine(reply.FullName); Console.ReadLine(); }
public IActionResult Index() { var client = new CustomerService.CustomerServiceClient(channel); CustomerList cust = client.GetAll(new Empty()); return(View(cust)); }
private void Form1_Load(object sender, EventArgs e) { CustomerService.CustomerServiceClient client = new CustomerService.CustomerServiceClient("NetTcpBinding_ICustomerService"); Customers = client.GetAll(0).ToList(); foreach(CustomerService.Customer customer in Customers) { listBox1.Items.Add(customer.Name); } }
public IActionResult DeleteConfirmed(int id) { var client = new CustomerService.CustomerServiceClient(channel); Empty response = client.Delete(new CustomerId() { Id = id }); return(RedirectToAction(nameof(Index))); }
public IActionResult Create(Customer customer) { if (ModelState.IsValid) { var client = new CustomerService.CustomerServiceClient(channel); var createdCustomer = client.Insert(customer); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var channel = new Channel("127.0.0.1:8081", ChannelCredentials.Insecure); var client = new CustomerService.CustomerServiceClient(channel); services.AddSingleton(client); services.AddTransient <ICustomerServiceRequester, CustomerServiceRequester>(); services.AddAutoMapper(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }
public ServiceFacade(IEventAggregator messageBus) { _messageBus = messageBus; if (_authenticationservice == null) { _authenticationservice = new AuthenticationServiceClient(); } if (_customerservice == null) { _customerservice = new CustomerServiceClient(); } }
public ServiceFacade(IEventAggregator messageBus ) { _messageBus = messageBus; if(_authenticationservice==null) { _authenticationservice= new AuthenticationServiceClient(); } if(_customerservice==null) { _customerservice = new CustomerServiceClient(); } }
public IActionResult Edit(int id, Customer customer) { if (id != customer.CustomerId) { return(NotFound()); } if (ModelState.IsValid) { var client = new CustomerService.CustomerServiceClient(channel); Customer response = client.Update(customer); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
protected void Button1_Click(object sender, EventArgs e) { CustomerService.CustomerServiceClient proxy = new CustomerService.CustomerServiceClient(); try { GridView1.DataSource = proxy.GetCustomerList(); GridView1.DataBind(); } catch (Exception ex) { // TODO: handle exception } finally { proxy.Close(); } }
private static async Task Main(string[] args) { Channel channel = new Channel("localhost:5000", ChannelCredentials.Insecure); var healthClient = new Health.HealthClient(channel); var healthResponse = await healthClient.CheckAsync(new HealthCheckRequest()); Console.WriteLine($"Server is: {healthResponse.Status}"); healthResponse = await healthClient.CheckAsync(new HealthCheckRequest { Service = CustomerService.Descriptor.Name }); Console.WriteLine($"CustomerService is: {healthResponse.Status}"); var customerClient = new CustomerService.CustomerServiceClient(channel); var customerResponse = await customerClient.GetCustomerByIdAsync( new GetCustomerByIdRequest { Id = 1 }, new CallOptions(new Metadata { { "correlation-id", Guid.NewGuid().ToString() } })).ResponseAsync.ConfigureAwait(false); Console.WriteLine($"Customer: {customerResponse.Customer.Id} retrieved."); customerResponse = await customerClient.GetCustomerById2Async( new GetCustomerByIdRequest { Id = 1 }, new CallOptions(new Metadata { { "correlation-id", Guid.NewGuid().ToString() } })).ResponseAsync.ConfigureAwait(false); Console.WriteLine($"Customer: {customerResponse.Customer.Id} retrieved."); var customerResponse2 = customerClient.DeleteCustomerById(new DeleteCustomerByIdRequest { Id = 1 }); var customerResponse3 = customerClient.ListCustomers(new CustomerSearch { FirstName = "test" }); while (await customerResponse3.ResponseStream.MoveNext(CancellationToken.None)) { var response = customerResponse3.ResponseStream.Current; } await channel.ShutdownAsync().ConfigureAwait(false); Console.ReadKey(); }
public IActionResult Edit(int?id) { if (id == null) { return(NotFound()); } var client = new CustomerService.CustomerServiceClient(channel); Customer customer = client.Get(new CustomerId() { Id = (int)id }); if (customer == null) { return(NotFound()); } return(View(customer)); }
protected void Page_Load(object sender, EventArgs e) { CustomerService.CustomerServiceClient customerClient = new CustomerService.CustomerServiceClient("BasicHttpBinding_ICustomerService"); Customers = customerClient.GetAll(0).ToList(); //LinqDataSource DataSource = new LinqDataSource(); //DataSource.ID = "LinqCustomers"; //DataSource.ContextTypeName = "CustomerWebClient.Index"; //DataSource.Select = "new(Id, Name, Email)"; //DataSource.TableName = "Customers"; //Controls.Add(DataSource); //GridView1.DataSourceID = "LinqCustomers"; foreach(CustomerService.Customer customer in Customers) { Response.Write("<p>" + customer.Name + "</p>"); } }
private static void TestCreateNewReservationforCustomer() { using (CustomerService.CustomerServiceClient proxy = new CustomerService.CustomerServiceClient()) { List <Trip> trips = proxy.GetUpcomingTrips(); Customer newCust = new Customer { FirstName = "Joan", LastName = "Amrat", InitialDate = DateTime.Now }; newCust.RowVersion = System.Text.Encoding.Default.GetBytes("0x123"); newCust.CustRowVersion = System.Text.Encoding.Default.GetBytes("0x123"); Reservation newRes = new Reservation(); newRes.Trip = trips[8]; newRes.RowVersion = System.Text.Encoding.Default.GetBytes("0x123"); newRes.ReservationDate = DateTime.Now; newCust.Reservations = new List <Reservation>(); newCust.Reservations.Add(newRes); proxy.InsertCustomer(newCust); } }
public async Task ShouldFailToIntercept() { var channel = new Channel("localhost", 5001, ChannelCredentials.Insecure); var options = Options.Create(new CallInterceptorOptions { ServiceName = "google.protobuf.CustomerService", ResponseType = "GetCustomerByIdResponse", JsonResponseContent = JsonConvert.SerializeObject(new AddCustomersResponse { Id = 1 }) }); var interceptor = new CallInterceptor(options, channel); var client = new CustomerService.CustomerServiceClient(interceptor); var exception = await Assert.ThrowsAsync <RpcException>(() => client.AddCustomers(new Metadata()).ResponseAsync); Assert.Equal(StatusCode.Unavailable, exception.StatusCode); }
public async Task ShouldIntercept() { var channel = new Channel("localhost", 5001, ChannelCredentials.Insecure); var options = Options.Create(new CallInterceptorOptions { ServiceName = "google.protobuf.CustomerService", ResponseType = "GetCustomerByIdResponse", JsonResponseContent = JsonConvert.SerializeObject(new GetCustomerByIdResponse { Customer = new Customer { Id = 1, FirstName = "Ed", LastName = "Torsten" } }) }); var interceptor = new CallInterceptor(options, channel); var client = new CustomerService.CustomerServiceClient(interceptor); GetCustomerByIdResponse response = await client.GetCustomerByIdAsync(new GetCustomerByIdRequest()); Assert.Equal(1, response.Customer.Id); Assert.Equal("Ed", response.Customer.FirstName); Assert.Equal("Torsten", response.Customer.LastName); }
public CustomerServiceRequester(CustomerService.CustomerServiceClient customerServiceClient) { _customerServiceClient = customerServiceClient; }
public CustomereApplicationService(CustomerIMapper mapperCustomer, CustomerService.CustomerServiceClient serviceGrpcCustomer) { this._mapperCustomer = mapperCustomer; this._serviceGrpcCustomer = serviceGrpcCustomer; }
static async Task Main(string[] args) { //AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); var customer = new Customer { ColorInConsole = GetRandomChatColor(), Id = Guid.NewGuid().ToString(), Name = args.Length > 0 ? args[0] : "TheHulk" }; //var channel = GrpcChannel.ForAddress("https://localhost:5001", new GrpcChannelOptions { Credentials = ChannelCredentials.Insecure }); var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new CustomerService.CustomerServiceClient(channel); var joinCustomerReply = await client.JoinCustomerChatAsync(new JoinCustomerRequest { Customer = customer }); client. using (var streaming = client.SendMessageToChatRoom(new Metadata { new Metadata.Entry("CustomerName", customer.Name) })) { CancellationTokenSource cts = new CancellationTokenSource(); var response = Task.Run(async() => { while (await streaming.ResponseStream.MoveNext()) { Console.ForegroundColor = Enum.Parse <ConsoleColor>(streaming.ResponseStream.Current.Color); Console.WriteLine($"{streaming.ResponseStream.Current.CustomerName}: {streaming.ResponseStream.Current.Message}"); Console.ForegroundColor = Enum.Parse <ConsoleColor>(customer.ColorInConsole); } Console.WriteLine("Exit Task.Run"); }, cts.Token); await streaming.RequestStream.WriteAsync(new ChatMessage { CustomerId = customer.Id, Color = customer.ColorInConsole, Message = "", RoomId = joinCustomerReply.RoomId, CustomerName = customer.Name }); Console.ForegroundColor = Enum.Parse <ConsoleColor>(customer.ColorInConsole); Console.WriteLine($"Joined the chat as {customer.Name}"); var line = Console.ReadLine(); DeletePrevConsoleLine(); while (!string.Equals(line, "qw!", StringComparison.OrdinalIgnoreCase)) { if (line == "wqwq") { Console.WriteLine($"Joined the chat as {customer.Name}"); } await streaming.RequestStream.WriteAsync(new ChatMessage { Color = customer.ColorInConsole, CustomerId = customer.Id, CustomerName = customer.Name, Message = line, RoomId = joinCustomerReply.RoomId }); line = Console.ReadLine(); DeletePrevConsoleLine(); } await streaming.RequestStream.CompleteAsync(); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
static void Main(string[] args) { CustomerService.CustomerServiceClient lClient = new CustomerService.CustomerServiceClient(); lClient.CreateCustomer(new CustomerService.Customer() { Name = "Matt", Address="1 Reynolds Street", Orders = new CustomerService.Order[0]}); }