开发者

Returning paged results from WebMethod?

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 Webmetho开发者_开发技巧d?

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

How can I accomplish that?


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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜