// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.Run(async(context) => { CacheDbService db = new CacheDbService("localhost"); db.ClearValues(); var c = new HttpClient(); List <Task> tasks = new List <Task>(); for (int t = 0; t < 100; t++) { tasks.Add(c.PostAsJsonAsync("http://localhost:30950/api/values", new Message { name = "Test" })); } Task.WaitAll(tasks.ToArray()); var data = string.Join('\n', db.Values()); await context.Response.WriteAsync(data); }); }
public async Task <string> Post([FromBody] Message value) { try { var message = $"{Guid.NewGuid()}:{value.name}"; CacheDbService db = new CacheDbService("host.docker.internal"); db.AddValue(message); // BloggingContext context = new BloggingContext(); // Blog entity = new Blog { Message = $"{DateTime.Now.ToShortTimeString()}:{value.name}" }; // context.Blogs.Add(entity); // await context.SaveChangesAsync(); return(message); } catch (System.Exception ex) { return(ex.ToString()); } }