Limiting number of results returned from webservice

Nov 11, 2010 at 8:55 PM

I am using the code to return a list of users that meet a certain criteria.

I was wondering if there was any way of limiting the results returned from the webservice.

eg Client.Enumerate('xpathquery', 0, 20) <- This would return only the first 20 records.

I've tried using position() in the XPath query, but I always get an error like "badly formed query" (or something like that).

Any ideas???


Nov 17, 2010 at 11:58 AM

Hi Grant,
sorry for the late (and quick) answer, but I'm very busy right now.

There is a way of limiting the results returned from the webservice. Explaining the thing in detail would take some time, but I can provide you with a code snippet that you could adapt to your needs.

It's in the form of an extension method, and does not use the DefaultClient, but directly the WsEnumerationClient:

        public static IEnumerable<RmResource> Query(
            this WsEnumerationClient client,
            string query,
            Sorting sorting,
            params string[] attributes) {

            EnumerationRequest request = new EnumerationRequest(query);
            if (null != sorting) {
                request.Sorting = sorting;
            request.MaxElements = Config.MaxElements;
            if (attributes != null && attributes.Length != 0) {
                attributes = attributes.AddMissingValues(
                request.Selection = new List<string>(attributes);
            EnumerateResponse response = client.Enumerate(request);
            foreach (RmResource resource in Fim.ResourceFactory.CreateResource(response)) {
                yield return resource;
            if (!response.IsEndOfSequence) {
                PullResponse pullResponse = null;
                EnumerationContext context = response.EnumerationContext;
                do {
                    PullRequest pullRequest = new PullRequest();
                    pullRequest.EnumerationContext = context;
                    // the Enumeration Context does not contain the sorting
                    // attribute!
                    pullRequest.EnumerationContext.Sorting = sorting;
                    pullRequest.MaxElements = Config.MaxElements;
                    pullResponse = client.Pull(pullRequest);
                    foreach (RmResource resource in Fim.ResourceFactory.CreateResource(pullResponse)) {
                        yield return resource;
                    context = pullResponse.EnumerationContext;
                } while (null != pullResponse && !pullResponse.IsEndOfSequence);
            yield break;

Hope this helps,