Skip to content

Instantly share code, notes, and snippets.

@mustakimali
Last active August 14, 2019 23:10
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 mustakimali/bdc8d4f7034ac8e985e3143976e571de to your computer and use it in GitHub Desktop.
Save mustakimali/bdc8d4f7034ac8e985e3143976e571de to your computer and use it in GitHub Desktop.
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Grpc.Net.Client;
using GrpcDotNetDemoPackage;
namespace Client
{
class Program
{
static async Task Main(string[] args)
{
var client = await GetClient();
var response = await client.SayHelloAsync(new HelloRequest
{
Name = "Mustakim"
});
Console.WriteLine(response.Hello);
}
private static Task<DemoService.DemoServiceClient> GetClient()
{
// This disables HTTPS
// https://github.com/aspnet/AspNetCore.Docs/issues/13120
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
var httpClient = new HttpClient
{
BaseAddress = new Uri("http://localhost:5000")
};
var client = GrpcClient.Create<DemoService.DemoServiceClient>(httpClient);
return Task.FromResult(client);
}
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Grpc.Net.Client" Version="0.1.22-pre2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Protos\Protos.csproj" />
</ItemGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment