views:

23

answers:

1

I am creating a web service in asp.net 2.0 with c# and have a web method which looks like this:

 [WebMethod()]
    public List<Comment> GetYourSayComments(int pageNumber, int pageSize, int commentTopicId)
    {
        CommentManager cm = new CommentManager();
        return cm.GetYourSayComments(pageNumber, pageSize, commentTopicId, true);

    }

This was working greate for the services that just returned all entities, this method however returns paged results. what is the best way to return the total row count to the client?

+1  A: 

You would have to create a custom type to include the count:

public class EnvelopeWithCount<T>
{
    public T Value { get; set; }
    public int RowCount { get; set; }
}

And then your web service would return the new type:

[WebMethod]
public EnvelopeWithCount<List<Comment>> GetYourSayComments(int pageNumber,
                                                           int pageSize,
                                                           int commentTopicId)
{
    CommentManager cm = new CommentManager();
    Envelope<List<Comment>> retrunVal = new Envelope<List<Comment>>();
    returnVal.Value = cm.GetYourSayComments(pageNumber,
                                            pageSize,
                                            commentTopicId,
                                            true);
    // Get the count of all rows however you need
    returnVal.RowCount = cm.GetYourSayComments(true).Count();

    return returnVal;
}
Justin Niessner
Do web services support this kind of Generic return type in .NET 2.0?
John K
@John - If they didn't, the original return value wouldn't have worked either.
Justin Niessner
thanks, thought thats what i would have to do but was hoping i could just make an attribute in the xml
aaron