Created
November 9, 2020 07:30
-
-
Save guitarrapc/0ebd76e92b33d4678ae0348da9d015f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ConsoleAppFramework; | |
using EchoGrpcMagicOnion.Shared; | |
using Grpc.Core; | |
using Grpc.Net.Client; | |
using MagicOnion.Client; | |
using Microsoft.Extensions.Hosting; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
namespace EchoGrpcMagicOnion.Client | |
{ | |
class Program : ConsoleAppBase, IMyHubReceiver | |
{ | |
static async Task Main(string[] args) | |
{ | |
await Host.CreateDefaultBuilder() | |
.RunConsoleAppFrameworkAsync<Program>(args); | |
} | |
[Command("Echo")] | |
public async Task Echo(string hostPort, string message, [Option("H")]string headers, [Option("v")]bool verbose = false) | |
{ | |
// under .NET Core 3.x: https://docs.microsoft.com/ja-jp/aspnet/core/grpc/troubleshoot?view=aspnetcore-3.1#call-insecure-grpc-services-with-net-core-client | |
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true); | |
await Task.Delay(TimeSpan.FromSeconds(3)); | |
var channel = GrpcChannel.ForAddress(hostPort); | |
var client = MagicOnionClient.Create<IEchoService>(channel, new IClientFilter[] | |
{ | |
new AppendHeaderFilter(headers), | |
new ResponseHandlingFilter(verbose), | |
}); | |
try | |
{ | |
var res = await client.EchoAsync(message); | |
Console.WriteLine(res); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine($"{ex.Message} {ex.StackTrace}"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment