Reputation: 101
Hi i have a simple WCF REST service, i need to get some parameters via querystring that looks like this.
page=1&rp=10&sortname=id&sortorder=asc&query=&qtype=Application
My UriTemplate not working, what is wrong here? just trying to get the page param so far. Any idea how the uri should look like?
[OperationContract]
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,RequestFormat = WebMessageFormat.Json,
UriTemplate = "/?page={page}")]
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
JSONData GetLogList(string page);
Here is my service code
public class LogService : ILog
{
[System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
public JSONData GetLogList(string page)
{
var logContext = new LogViewDataContext();
var logsList = from logs in logContext.Logs select logs;
//return logsList.Cast<Log>().ToString();
var baseData = new JSONData();
baseData.page = Int32.Parse(page ?? "1");
baseData.total = logsList.Count();
var cells = new ArrayList();
var tmplist = new List<JSONDataRow>();
foreach(var log in logsList)
{
var row = new JSONDataRow();
row.id = log.ID;
cells.Add(value: log.Date);
cells.Add(value: log.Application);
cells.Add(value: log.Server);
cells.Add(value: log.Message);
row.cell = cells;
tmplist.Add(row);
}
int x = Int32.Parse(page);
int pageSize = 10;
baseData.rows = tmplist.Skip((x - 1) * pageSize).Take(pageSize).ToList();
return baseData;
}
}
Here is the javascript that calling the service.
<script type="text/javascript">
$(document).ready(function() {
$("#logGrid").flexigrid({
type: 'POST',
url: 'http://MyWeb/Services/LogService.svc/',
contentType: "application/json; charset=utf-8",
dataType: "json",
colModel: [
{ display: 'Date', name: 'Date', width: 40, sortable: true, align: 'left' },
{ display: 'Application', name: 'Application', width: 150, sortable: true, align: 'left' },
{ display: 'Server', name: 'Server', width: 150, sortable: true, align: 'left' },
{ display: 'Message', name: 'Message', width: 250, sortable: true, align: 'left' }
],
searchitems: [
{ display: 'Date', name: 'Date' },
{ display: 'Application', name: 'Application', isdefault: true },
{ display: 'Server', name: 'Server' }
],
sortname: "id",
sortorder: "asc",
usepager: true,
title: "test",
useRp: true,
rp: 10,
showTableToggleBtn: false,
resizable: false,
width: 700,
height: 370,
singleSelect: true
});
});
</script>
Upvotes: 3
Views: 8675
Reputation: 7876
Can you set your URITemplate as follows:
URITemplate="/GetLogList?page={page}"
Then your URL from jquery should be like:
http://MyWeb/Services/LogService.svc/GetLogList?page=1
UPDATE:
If you want the other parameters as in your query string just append them to the URItemplate
Ex:
URITemplate="/GetLogList?page={page}&sortorder={sortorder}"
And then just have your method to have that parameter
JSONData GetLogList(string page, string sortorder);
Try to inspect the complete request with Fiddler when making the request.
Upvotes: 6