0

I have a ASP.NET Web API copy data from a third party application, and I am figuring out different options to reduce the response time of my API methods. API receives data and inserts into a table and then returns an HTTP Ok response. I would want to have the data copied and send a response back to the third party application and then do the processing of writing to the table.

    public IHttpActionResult Post()
    {
            var ds = ReadFully(Request.Content.ReadAsStreamAsync().Result);
            var dl = Encoding.UTF8.GetString(ds).Split(new string[] { Environment.NewLine, @"\r" }, StringSplitOptions.None).ToList();
            write(dl);

            if (errors.Count == 0)
                return Ok("Success..");
            else
                return BadRequest("Error..");

    }

    public static byte[] ReadFully(Stream stream)
    {
        using (MemoryStream ms = new MemoryStream())
        {
            stream.CopyTo(ms);
            return ms.ToArray();
        }
    }
paone
  • 828
  • 8
  • 18
  • So... what's the question? What's the point of copying the entire request content? – Camilo Terevinto Feb 02 '18 at 19:16
  • May be a duplicate of https://stackoverflow.com/a/27062690/2071241 . Mind that the asp.net application pool may restart anytime and your background threads will be forced to terminate. – Lucas Feb 02 '18 at 19:28
  • I am looking at options to do the processing asynchronously. Firstly copy data and send a response back to the third-party application. And then do the processing of writing to a table. Is there a way to copy data to byte[] array within the Post() method and send the response back? – paone Feb 02 '18 at 19:50

0 Answers0