Служба OData не возвращает полный ответ - PullRequest
3 голосов
/ 15 июня 2011

Я читаю данные списка 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

Ответы [ 3 ]

6 голосов
/ 16 июня 2011

Видите ли вы элемент <link rel="next"> в конце канала?

Например, если вы посмотрите на

http://services.odata.org/Northwind/Northwind.svc/Customers/

, вы увидите

<link rel="next" href="http://services.odata.org/Northwind/Northwind.svc/Customers/?$skiptoken='ERNSH'" />

в конце канала, что означает, что служба реализует пейджинг на стороне сервера, и вам необходимо отправить запрос

http://services.odata.org/Northwind/Northwind.svc/Customers/?$skiptoken='ERNSH' 

, чтобы получить следующий набор результатов.

0 голосов
/ 27 апреля 2016

У меня была такая же проблема, и я хотел, чтобы это было общее решение.Поэтому я расширил 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;
    }
0 голосов
/ 19 июня 2011

Я не вижу ничего особенно плохого в вашем коде. Вы можете попытаться сбросить запрошенный beign 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);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...