2

QueryOperationResponse GetContinuation() メソッドを使用して、odata wcf フィードから読み取った非常に大きなデータ セットをページングしようとしています。Microsoft から取得したいくつかの OData ヘルパー ライブラリを使用しています。

問題は、ページング プロセスが無限ループに陥ったように見え、決して終了しないことです。たとえば、ページ サイズを 10000 レコードに設定し、取得するレコードが 80000 ある場合、ループが 8 回以上繰り返され、終了する必要があることがわかります。

以下は、サービスをクエリし、ページングを実装するクラスです (下部にあります)。また、NextLinkUri の 'OriginalString' が反復ごとに変更されないことも確認しましたが、これは間違っていると思いますか? 本当に明白な何かが欠けていることを願っています。これがページへの正しい方法だと思います:

    private static IList<dynamic> Get(string serviceUri, NameValueCollection queryOptions, IAuthenticationScheme authenticationScheme)
    {
        string baseUri;
        string entitySet;
        string entityKey;
        string queryString;
        ValidateServiceUri(serviceUri, out baseUri, out entitySet, out entityKey, out queryString);
        string resource = !string.IsNullOrEmpty(entityKey) ? entitySet + "(" + entityKey + ")" : entitySet;

        DataServiceContext context = new DataServiceContext(new Uri(baseUri));
        context.IgnoreMissingProperties = true;

        DataServiceContextHandler handler = new DataServiceContextHandler(authenticationScheme);
        handler.HandleGet(context);

        DataServiceQuery<EntryProxyObject> query = context.CreateQuery<EntryProxyObject>(resource);

        NameValueCollection options = HttpUtility.ParseQueryString(queryString);
        options.Add(queryOptions);

        foreach (string key in options.AllKeys)
        {
            query = query.AddQueryOption(key, options[key]);
        }

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

        IList<dynamic> result;
        if (options["$inlinecount"] == "allpages")
        {
            result = new DynamicEntityCollection(response.TotalCount) as IList<dynamic>;
        }
        else
        {
            result = new List<dynamic>();
        }

        foreach (EntryProxyObject proxy in response)
        {
            DynamicEntity entity = new DynamicEntity(proxy.Properties);
            result.Add(entity);
        }

        while (response.GetContinuation() != null)
        {
            DataServiceQueryContinuation<EntryProxyObject> continuation = response.GetContinuation();
            QueryOperationResponse<EntryProxyObject> nextResponse = context.Execute<EntryProxyObject>(continuation);

            Console.WriteLine("Uri: " + continuation.NextLinkUri.OriginalString); 

            foreach (EntryProxyObject proxy in nextResponse)
            {
                DynamicEntity entity = new DynamicEntity(proxy.Properties);
                result.Add(entity);
            }
        }

        return result;
    }

これは私がメソッドを呼び出す方法です:

return OData.Get("http://xxx.x.xxx.xx/MyDataService.svc/MyProducts", "$filter=Index gt 0");
4

1 に答える 1

4

あなたは常に最初の反応の続きを見ています。それは一定のままです(明らかな理由により)。コード内の nextResponse の続きを調べて、読み取るデータがまだあるかどうかを判断し、次のページを取得するために続きを取得する必要があります。上記のコードは、最初のページを読み取り、次に 2 ページ目を何度も読み取ります。

于 2011-03-25T10:24:15.433 に答える