jQuery UI Widgets › Forums › Grid › Cannot make server side paging work with ASP.NET Web Service
Tagged: asp.net webservice, grid, http error, paging
This topic contains 7 replies, has 2 voices, and was last updated by sdalby 12 years, 1 month ago.
-
Author
-
Hi I have following grid Data Source
source = { url: 'EodOverviewWebService.asmx/GetOverviewLines', contentType: 'application/json; charset=utf-8', datatype: "json", datafields: [ { name: 'Id' }, { name: 'TimeToFire' }, { name: 'SysDate' }, { name: 'NewDate' }, { name: 'Status' }, { name: 'ReasonForExecution' }, { name: 'ModulesExecuted' } ], async: false, formatdata: function (data) { return { pagenum: data.pagenum, pagesize: data.pagesize }; }};
Which calls method:
[WebMethod(EnableSession = true)][ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]public List<EodRow> GetOverviewLines(int pagenum, int pagesize)
This causes the grid to make following call:
GET /Cob/EodOverviewWebService.asmx/GetOverviewLines?pagenum=0&pagesize=10 HTTP/1.1
which in turn produces following error message:
Request format is unrecognized for URL unexpectedly ending in '/GetOverviewLines'.
Can you assist?
I have been stuck for many days now. Hope you can help. Do I need to change this into an ASP.NET generic handler in order to make it work? I that would be a huge step back.
Thanks in advance
Soeren DalbyI think that I have found out why there is a problem here and it appears as if you have a bug in your way of accessing WebServices
It is explained here:
http://encosia.com/asmx-scriptservice-mistake-invalid-json-primitive/
basically, it explains why use of parameters causes contentType to be changed to
application/x-www-form-urlencoded
which in turn causes ASMX Web Services to malfunction.
It also explains how to fix it.
The fix is to use ‘data’ to assign parameters rather than using url’ values. Can I overwrite your default behaviour in order to do this?
hi sdalby,
I suggest you to take a look at the ASP .NET Integration help topics as they are built from ASP .NET, ASP .NET MVC examples and also Grid’s help topics, especially this one: jquery-grid-extra-http-variables.htm.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi Peter
Yes the page
adresses this issue and comes up with a solution for $.ajax calls, but none that I can utilize for the datasource. It still translates into a text/hml call which makes ASMX services return XML rather than JSON.
I have however managed to make it work a ASP.NET Generic handler and while this is far from an elegant solution it works, and I have been stuck with this for a week now, so I will let it be for now.
Thanks for your assistance.
Soeren
Hi Soeren,
I took a look at your code again and saw that you set the contentType property of the source object. However, the property’s name is contenttype not contentType.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi
Your right, it did make a different, which is a bit confusing since ‘contentType’ is used for $.ajax calls
How ever it just makes the ASMX service give a more correct error:
Invalid JSON primitive: pagenum.
which is correct according to the above referenced document, because http POST/GET parameters cannot be used in a JSON call unless passed on as a ‘data’ object.
It does however appear as if WCF OData based services can handle it, according to your examples. You should be aware of though, that ASMX is the widespread choice for .NET developers.
Thanks for your assistance 🙂
Soeren
Hi Soeren,
Actually, the jqxDataAdapter makes exactly Ajax call under the hood and all properties and settings available in the jQuery’s Ajax function are exposed and can be set – see: jquery-data-adapter.htm and jquery-grid-datasources.htm. The help topic: jquery-grid-extra-http-variables.htm demonstrates how to pass data to a server.
Best Regards,
Peter StoevjQWidgets Team
http://www.jqwidgets.comHi again,
Actually I have to move on – I cannot spend more time on this now and I have something that works.
Thanks for all your help
-
AuthorPosts
You must be logged in to reply to this topic.