static void Main(string[] args) { _channel = new Channel("localhost", 12345, ChannelCredentials.Insecure); // get MagicOnion dynamic client proxy _client = MagicOnionClient.Create <IMyFirstService>(_channel); testy(); }
static async Task UnaryRun(IMyFirstService client) { try { var vvvvv = await await client.SumAsync(10, 20); Console.WriteLine("SumAsync:" + vvvvv); var v2 = await client.SumAsync2(999, 1000); Console.WriteLine("v2:" + v2); } catch (Exception ex) { Console.WriteLine(ex); } }
static async Task ServerStreamRun(IMyFirstService client) { try { var stream = await client.StreamingTwo(10, 20, 3); await stream.ResponseStream.ForEachAsync(x => { Console.WriteLine("ServerStream Response:" + x); }); var stream2 = client.StreamingTwo2(10, 20, 3); await stream2.ResponseStream.ForEachAsync(x => { }); } catch (Exception ex) { Console.WriteLine(ex); } }
static void Main(string[] args) { const string serviceURL = "http://192.168.0.109:8732/Design_Time_Addresses/MyFirstService"; ChannelFactory <IMyFirstService> channelFactory = new ChannelFactory <IMyFirstService>( new BasicHttpBinding(), new EndpointAddress(serviceURL)); IMyFirstService myFirstService = channelFactory.CreateChannel(); Console.WriteLine("This console application is a client for the MyFirstService WCF service"); Console.WriteLine(string.Format("It tries to use the service at address: {0}", serviceURL)); Console.WriteLine(); Console.Write("Write text to get number of words: "); string s = Console.ReadLine(); int numberWords = myFirstService.GetNumberWords(s); Console.WriteLine(string.Format("Number of words: {0}", numberWords)); }
static async Task ClientStreamRun(IMyFirstService client) { try { var stream = await client.StreamingOne(); for (int i = 0; i < 3; i++) { await stream.RequestStream.WriteAsync(i); } await stream.RequestStream.CompleteAsync(); var response = await stream.ResponseAsync; Console.WriteLine("Response:" + response); } catch (Exception ex) { Console.WriteLine(ex); } }
static async Task UnaryLoadTest(IMyFirstService client) { const int requestCount = 100000; ThreadPool.SetMinThreads(1000, 1000); var sw = Stopwatch.StartNew(); Task[] t = new Task[requestCount]; for (int i = 0; i < requestCount; i++) { t[i] = (client.SumAsync(i, i).ContinueWith(y => y.Result.ResponseAsync).Unwrap()); } await Task.WhenAll(t); sw.Stop(); Console.WriteLine(sw.Elapsed.TotalMilliseconds + "ms"); // 10000request, x-ms var one = sw.Elapsed.TotalMilliseconds / requestCount; // 1request, ms Console.WriteLine(one); Console.WriteLine((1000.0 / one) + "req per/sec"); }
static async Task DuplexStreamRun(IMyFirstService client) { try { var stream = await client.StreamingThree(); var count = 0; await stream.ResponseStream.ForEachAsync(async x => { Console.WriteLine("DuplexStream Response:" + x); await stream.RequestStream.WriteAsync(count++); if (x == "finish") { await stream.RequestStream.CompleteAsync(); } }); } catch (Exception ex) { Console.WriteLine(ex); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IMyFirstService myService) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseStaticFiles(); app.UseFancyMiddleware(); app.Map("/map1", b => { b.Run(c => c.Response.WriteAsync("first map1")); }); app.Map("/myservice", b2 => { b2.Run(async c => { var t = await myService.DoWork(); await c.Response.WriteAsync($"Hello from service with {t}"); }); }); app.MapWhen(c => { return(c.Request.Path.StartsWithSegments("/sample4") && c.Request.Method == "POST"); }, b => { b.Run(c => { return(c.Response.WriteAsync($"User entered:{c.Request.Form["text1"]}")); }); }); app.MapWhen(c => { return(c.Request.Path.StartsWithSegments("/form") && c.Request.Method == "GET"); }, b1 => { b1.Run(c => { return(c.Response.WriteAsync(File.ReadAllText("wwwroot/htmlpage.html"))); }); }); app.Run(async(context) => { context.Request.Query.TryGetValue("x", out StringValues val); var v = val == StringValues.Empty ? null : HtmlEncoder.Default.Encode(val); await context.Response.WriteAsync($"Hello World! {v}"); }); }
public ValuesController(IHttpContextAccessor accessor, IMyFirstService myFirstService) { _accessor = accessor; _myFirstService = myFirstService; }
public TestClient() { channel = new Channel("localhost", 12345, ChannelCredentials.Insecure); client = MagicOnionClient.Create <IMyFirstService>(channel); }