0

I have a class that posts data to a web API which then processes the large object and generates corresponding db records. I am dealing with a fairly large object that has multiple types of sub-objects in it. This is the code that I have:

var content = new StringContent(JsonConvert.SerializeObject(largeObject), Encoding.UTF8, "application/json");
var response = client.PostAsync(serviceEndpointURL,content).Result;

This returns SystemOutOfMemoryException understandably, but I am not sure how I can design this to support such large objects.

Jason Chang
  • 105
  • 1
  • 7

2 Answers2

0

Passing larger number of objects thought Web API will not be reliable. You need to think different option for design your solution. You can use some message queue(i.e RabbitMQ) service and backend message handler. Web API Create some job request and message handler will process message in backend.

jalil
  • 85
  • 10
  • i think we may need more context before drawing the big gun. Also when already struggling at this point this can't help – Bombinosh Feb 27 '19 at 22:34
0

Alternatively, I have also tried this, but here as well, it errors at the ser.Serialize() line with same exception.

var content = new PushStreamContent((stream, httpContent, transportContext) =>
{
    using (var tw = new StreamWriter(stream))
    {
        var ser = new JsonSerializer();
        ser.Serialize(tw, largeObject);
    }
});

var response = client.PostAsync(serviceEndpointURL,content).Result;
Jason Chang
  • 105
  • 1
  • 7