I've made a WCF Service that sends a JSON string to some client. I've been requested to make some kinda pagination so it doesn't just send all the data at once, but I'm unsure on how best to go about this. The stuff I've read online so far seems either pretty vague or not really applicable to my specific application, atleast not in a way I understand.
Here's how my WCF works:
Got an IService1:
[OperationContract()]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, UriTemplate = "/BP?vCaseNr={vCaseNr}")]
Stream BoligPraesentation(string vCaseNr);
Service1:
public Stream BoligPraesentation(string vSagsNr)
{
SqlConnection con = new SqlConnection();
con = Database();
SqlDataAdapter dau = new SqlDataAdapter(*long sql here*, con);
DataTable dtu = new DataTable();
dau.Fill(dtu);
string json = GetJson(dtu)
if (json != "[]")
{
json = json.Replace("[", "");
json = json.Replace("]", "");
json = "{\"Things\": [" + json + "]}";
}
WebOperationContext.Current.OutgoingResponse.ContentType =
"application/json; charset=utf-8";
return new MemoryStream(Encoding.UTF8.GetBytes(json));
}
The GetJSon looks like this:
private string GetJson(DataTable dt)
{
System.Web.Script.Serialization.JavaScriptSerializer Jserializer = new System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>> rowsList = new List<Dictionary<string, object>>();
Dictionary<string, object> row = null;
foreach (DataRow dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn col in dt.Columns)
{
row.Add(col.ColumnName, dr[col]);
}
rowsList.Add(row);
}
return Jserializer.Serialize(rowsList);
}
The JSON looks kinda like this after it's been returned:
{"Things": [{"CaseNr":6,"Titel":"some place V","Areal":null,"Adresse1":"Hsome address","Rum":2,"Etage":0,"PostNr":"9999","ByNavn":"city","EjendomNavn":"name here","Status":"LEDIG","Leje":"343434","AntalBilleder":0,"AntalProspekter":0,"AntalKort":0,"AntalTegninger":0},{"CaseNr":4,"Titel":"big place","Areal":null,"Adresse1":"adress 555","Rum":null,"Etage":3,"PostNr":"2222","ByNavn":"Germacity","EjendomNavn":"HSbuilding ApS","Status":"OPTAGET","Leje":"0.00","AntalBilleder":0,"AntalProspekter":0,"AntalKort":0,"AntalTegninger":0}
Instead of sending all Things over at the same time(there can be way more than the two I showed) I would like to send 20 at a time, or perhaps let the client decide how many. I'm not at all sure how to make this work though, any advice?
PS: Please say if I need to show more info.