views:

31

answers:

1

I need to create WebMethod that will get some data from db and return that to the client.

Now, assume that the amount of data is huge, so I'd like to take and return data in parts.

is there any way to use yield return in Webmethod?

as I know there is no way to return generic types in WebMethods but I couldn't use non-generic IEnumerable as well...

Gimme pls, some idea how to accomplish that...

+2  A: 

No, you can't yield return from a WebMethod. But you can add two parameters to the method call to allow paged results:

public string[] GetResults(string someQuery)
{
    var results = new List<string>();

    // Fill Results

    return results.ToArray();
}

Becomes:

public string[] GetResults(string someQuery, int pageNum, int pageSize)
{
    var results = new List<string>();

    // Fill Results

    return results.Skip(pageNum * pageSize).Take(pageSize).ToArray();
}
Justin Niessner
On this, he may want to expose a value that indicates the number of results there are in the total resultset. Also, from a web service point of view, he might not want the page size to be a user-supplied value, but rather a limit of the service (or at least test for an upper bound, wouldn't want a client to try to grab a billion results at once).
Anthony Pegram