Услугата 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)


Виждате ли елемент <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' 

заявка, за да получите следващия набор от резултати.

person Turker    schedule 16.06.2011

Не виждам нищо особено лошо в кода ти. Можете да опитате да изхвърлите 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