Skip to content

Commit

Permalink
Update GrpcClient to client ctor on channel (#15448)
Browse files Browse the repository at this point in the history
* Update GrpcClient to client ctor on channel

Fixes #14136

* Remove duplicated code sections
  • Loading branch information
jongalloway authored and Rick-Anderson committed Nov 2, 2019
1 parent 0cbcd8f commit cb10474
Showing 1 changed file with 4 additions and 37 deletions.
41 changes: 4 additions & 37 deletions aspnetcore/tutorials/grpc/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,9 @@ namespace GrpcGreeterClient
{
static async Task Main(string[] args)
{
var httpClient = new HttpClient();
// The port number(5001) must match the port of the gRPC server.
httpClient.BaseAddress = new Uri("https://localhost:5001");
var client = GrpcClient.Create<Greeter.GreeterClient>(httpClient);
var channel = GrpcChannel.ForAddress("https://localhost:5001");
var client = new Greeter.GreeterClient(channel);
var reply = await client.SayHelloAsync(
new HelloRequest { Name = "GreeterClient" });
Console.WriteLine("Greeting: " + reply.Message);
Expand All @@ -159,40 +158,8 @@ namespace GrpcGreeterClient

The Greeter client is created by:

* Instantiating an `HttpClient` containing the information for creating the connection to the gRPC service.
* Using the `HttpClient` to construct the Greeter client:

```csharp
static async Task Main(string[] args)
{
var httpClient = new HttpClient();
// The port number(5001) must match the port of the gRPC server.
httpClient.BaseAddress = new Uri("https://localhost:5001");
var client = GrpcClient.Create<Greeter.GreeterClient>(httpClient);
var reply = await client.SayHelloAsync(
new HelloRequest { Name = "GreeterClient" });
Console.WriteLine("Greeting: " + reply.Message);
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
```

The Greeter client calls the asynchronous `SayHello` method. The result of the `SayHello` call is displayed:

```csharp
static async Task Main(string[] args)
{
var httpClient = new HttpClient();
// The port number(5001) must match the port of the gRPC server.
httpClient.BaseAddress = new Uri("https://localhost:5001");
var client = GrpcClient.Create<Greeter.GreeterClient>(httpClient);
var reply = await client.SayHelloAsync(
new HelloRequest { Name = "GreeterClient" });
Console.WriteLine("Greeting: " + reply.Message);
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
```
* Instantiating a `GrpcChannel` containing the information for creating the connection to the gRPC service.
* Using the `GrpcChannel` to construct the Greeter client.

## Test the gRPC client with the gRPC Greeter service

Expand Down

0 comments on commit cb10474

Please sign in to comment.