Skip to content

Instantly share code, notes, and snippets.

@tuannguyenssu
Created August 10, 2019 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuannguyenssu/e737c6414786ffae1dd0c844886e24fb to your computer and use it in GitHub Desktop.
Save tuannguyenssu/e737c6414786ffae1dd0c844886e24fb to your computer and use it in GitHub Desktop.
using Grpc.Core;
using Grpc.Net.Client;
using GrpcUserEndpoint;
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace GrpcClientTest
{
class Program
{
static async Task Main(string[] args)
{
Console.WriteLine("Starting GRPC Client...");
Console.WriteLine();
var httpClient = new HttpClient();
string grpcServerUrl = "https://localhost:5001";
httpClient.BaseAddress = new Uri(grpcServerUrl);
var client = GrpcClient.Create<GrpcUser.GrpcUserClient>(httpClient);
try
{
var response = await client.GetUserAsync(new GetUserRequest { Id = "123" });
Console.WriteLine("Response from server : ");
Console.WriteLine("Id: " + response.Id);
Console.WriteLine("Name: " + response.Name);
}
catch (RpcException ex)
{
if (ex.StatusCode == StatusCode.NotFound)
{
Console.WriteLine(ex.Status.Detail);
}
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment