Limiting number of results returned from webservice

Nov 11, 2010 at 9: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???

Regards,
Grant

Coordinator
Nov 17, 2010 at 12:58 PM

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(
                    AttributeNames.ObjectType,
                    AttributeNames.ObjectID);
                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,

Paolo