Getting the next record from a web service

2019-09-06 13:27发布

问题:

I have a very irritating problem. I'm working with a list of documents, but it's too big for the web service to handle correctly. Basically, it's a simple setup:

  1. An entity framework wraps around a table that contains thousands of large XML files as Text fields, with additional data. (1 GB in data.)
  2. A DataServiceHost REST service wraps around this document entity to send the data to a client application.
  3. A client application is calling the REST service to retrieve documents.

I cannot modify the server/service code. All I can work with is the client. And the client connects easily to this REST/web service and is able to retrieve data. But when accessing the documents that it has stored, I run into problems, most likely because it tries to send the whole list from server to client. And 1 GB of data is way too much. So, the service is called XMLData, the data is DocumentEntity. Something like:

foreach (DocumentEntity Document in XMLData.Documents)
{
    DoSomething(Document);
}

Fails, since it loads all documents first. It then fails with "Object reference not set to an instance of an object." possibly because the server times out or whatever. Doing the same with another table/entity on the same server just works fine. Now, by using XMLData.Documents.First() I can access the first record without any problems. But how do I tell the system to get the next one? That way, I can iterate through all documents one by one...

And again, I cannot modify the service code. Only the client code. The service is fixed in production.

回答1:

I'm assuming XMLData.Documents is some kind of collection. Have you tried XMLData.Documents.Skip(N).Take(1);?



标签: c# asp.net rest