// TODO:more createClient overload.
 public T CreateClient <T>()
     where T : IService <T>
 {
     return(MagicOnionClient.Create <T>(channel)
            .WithHeaders(new Metadata {
         { ChannelContext.HeaderKey, ConnectionId }
     }));
 }
Example #2
0
 public T CreateClient <T>(Func <Channel, CallInvoker> callInvokerFactory, IFormatterResolver resolver)
     where T : IService <T>
 {
     return(MagicOnionClient.Create <T>(callInvokerFactory(channel), resolver)
            .WithHeaders(new Metadata {
         { ChannelContext.HeaderKey, ConnectionId }
     })
            .WithCancellationToken(cancellationTokenSource.Token));
 }
        public T CreateClient <T>(Metadata metadata)
            where T : IService <T>
        {
            var newMetadata = new Metadata();

            for (int i = 0; i < metadata.Count; i++)
            {
                newMetadata.Add(metadata[i]);
            }
            newMetadata.Add(ChannelContext.HeaderKey, ConnectionId);

            return(MagicOnionClient.Create <T>(channel).WithHeaders(newMetadata).WithCancellationToken(cancellationTokenSource.Token));
        }
Example #4
0
        public T CreateClient <T>(Func <Channel, CallInvoker> callInvokerFactory, Metadata metadata, IFormatterResolver resolver)
            where T : IService <T>
        {
            var newMetadata = new Metadata();

            for (int i = 0; i < metadata.Count; i++)
            {
                newMetadata.Add(metadata[i]);
            }
            newMetadata.Add(ChannelContext.HeaderKey, ConnectionId);

            return(MagicOnionClient.Create <T>(callInvokerFactory(channel), resolver).WithHeaders(newMetadata).WithCancellationToken(cancellationTokenSource.Token));
        }
Example #5
0
        static async Task MainAsync()
        {
            var host = Environment.GetEnvironmentVariable("GRPC_HOST") ?? "localhost";

            int.TryParse(Environment.GetEnvironmentVariable("GRPC_PORT") ?? "12345", out var port);
            int.TryParse(Environment.GetEnvironmentVariable("TURNS") ?? "1", out var turns);
            var channel = new Channel(host, port, ChannelCredentials.Insecure);

            var client = MagicOnionClient.Create <IMyFirstService>(channel);

            // call method.
            var result = await client.SumAsync(100, 200);

            Console.WriteLine("Client Received:" + result);

            for (int i = 0; i < turns; i++)
            {
                var tasks = Enumerable.Range(1, 100)
                            .Select(id => Emulate(channel, id))
                            .ToArray();

                await Task.WhenAll(tasks);
            }
        }