Служба OData не возвращает полный ответ

Я читаю данные списка Sharepoint (> 20000 записей) с помощью службы Odata RESTful, как подробно описано здесь - http://blogs.msdn.com/b/ericwhite/archive/2010/12/09/getting-started-using-the-odata -rest-api-to-query-a-sharepoint-list.aspx

Я могу читать данные, но получаю только первые 1000 записей. Я также проверил, что регулировка представления списка установлена ​​на 5000 на сервере sharepoint. Добрый совет.

Обновление:

@Turker: Ваш ответ точен !! Большое тебе спасибо. Мне удалось получить первые 2000 записей в первой итерации. Однако я получаю одни и те же записи на каждой итерации цикла while. Мой код выглядит следующим образом:

                         ...initial code...
                     int skipCount =0;
  while (((QueryOperationResponse)query).GetContinuation() != null)
                {
                    //query for the next partial set of customers
                    query = dc.Execute<CATrackingItem>(
                        ((QueryOperationResponse)query).GetContinuation().NextLinkUri
                        );

                    //Add the next set of customers to the full list
                    caList.AddRange(query.ToList());

                    var results = from d in caList.Skip(skipCount)
                                  select new
                                  {
                                      Actionable = Actionable,
                                    };  Created = d.Created,

                        foreach (var res in results)
                        {

                            structListColumns.Actionable = res.Actionable;
                            structListColumns.Created= res.Created;
                        }
                         skipCount = caList.Count;
                     }//Close of while loop

person Atul    schedule 15.06.2011    source источник


Ответы (3)



Я не вижу ничего особенно плохого в вашем коде. Вы можете попытаться сбросить запрошенные URL-адреса (либо из кода, либо с помощью чего-то вроде fiddler), чтобы увидеть, действительно ли клиент отправляет те же запросы (и, таким образом, получает те же ответы).

В любом случае, вот пример кода, который действительно работает (с использованием примера сервиса):

DataServiceContext ctx = new DataServiceContext(new Uri("http://services.odata.org/Northwind/Northwind.svc"));

QueryOperationResponse<Customer> response = (QueryOperationResponse<Customer>)ctx.CreateQuery<Customer>("Customers").Execute();
do
{
    foreach (Customer c in response)
    {
        Console.WriteLine(c.CustomerID);
    }

    DataServiceQueryContinuation<Customer> continuation = response.GetContinuation();
    if (continuation != null)
    {
        response = ctx.Execute(continuation);
    }
    else
    {
        response = null;
    }
} while (response != null);
person Vitek Karas MSFT    schedule 18.06.2011

У меня была та же проблема, и я хотел, чтобы это было общее решение. Итак, я расширил DataServiceContext методом GetAlltems.

    public static List<T> GetAlltems<T>(this DataServiceContext context)
    {
        return context.GetAlltems<T>(null);
    }

    public static List<T> GetAlltems<T>(this DataServiceContext context, IQueryable<T> queryable)
    {
        List<T> allItems = new List<T>();
        DataServiceQueryContinuation<T> token = null;

        EntitySetAttribute attr = (EntitySetAttribute)typeof(T).GetCustomAttributes(typeof(EntitySetAttribute), false).First();

        // Execute the query for all customers and get the response object.
        DataServiceQuery<T> query = null;

        if (queryable == null)
        {
            query = context.CreateQuery<T>(attr.EntitySet);
        }
        else
        {
            query = (DataServiceQuery<T>) queryable;
        }

        QueryOperationResponse<T> response = query.Execute() as QueryOperationResponse<T>;

        // With a paged response from the service, use a do...while loop 
        // to enumerate the results before getting the next link.
        do
        {
            // If nextLink is not null, then there is a new page to load.
            if (token != null)
            {
                // Load the new page from the next link URI.
                response = context.Execute<T>(token);
            }

            allItems.AddRange(response);
        }
        // Get the next link, and continue while there is a next link.
        while ((token = response.GetContinuation()) != null);

        return allItems;
    }
person SolarX    schedule 27.04.2016