last day (15 days later) » 

6:08 PM
0
A: What does the maxJsonLength property refer to?

OlegYou mean probably System.Web.Script.Serialization.JavaScriptSerializer.MaxJsonLength property which need be increased globally if you use WebServices interface in the server code. The solution was describe in the answer for example. You ask about the background information of the problem. To tel...

 
Oleg - thanks for the information, although I'm not sure I follow your last paragraph. I'm using web forms to take advantage of membership services, and am in need of a fixed header type grid to display results from a stored procedure - thus my usage of jqGrid. In my research on it, I actually downloaded your VS project, but it seemed a lot for what I needed to do.
Also, this is a new project, and am just starting to code in C#. So I take it that the answer is that there is a limitation on the amount of json data returned, and I could run into an issue with a large result set.
 
If you just starting to code in C# then I would recommend you to use ASP.NET MVC5 and implement the controller action, which just return all data returned from STORED PROCEDURE. You should just add loadonce: true jqGrid option. Then jqGrid will makes paging/filtering/sorting of all data locally. MVC5 uses Newtonsoft.Json by default if you just return Json(listOfItems, JsonRequestBehavior.AllowGet) from the controller action. Thus you need just prepare List<items> from the results of call of STORED PROCEDURE.
 
I used Nuget and installed Newtonsoft.Json. My stored procedure fills a datatable - dt, so I converted it to a json string by doing: string json = JsonConvert.SerializeObject(dt); Now I'm back to the drawing board with jqgrid, trying to display this. Not sure how to show code in comments on here. Thanks for the heads up on Newtonsoft.Json - I'll remove the max length from web.config
 
@Brian: You are welcome! Is jqGrid will be filled successfuly now with large data? If you need to post some code then you should do always the following: click "edit" link/button below the text of your question, append your text with words like UPDATED: or UPDATED 2: and then append any code or additional information, finally you should write short comment to inform other that you posted additional information at the end of the text of your question.
 
No - not yet. My previous implementation was using the java serializers. I'm not much of a guru when it comes to this stuff - yet... Going to look at your example to see what it is doing with the json string data to display in jqgrid.
Oleg, took your advice, but get the same results. See update above.
 
6:08 PM
@Brian: You should always post the code. I see your errors in 1 sec. The line [WebMethod] means that you misunderstood me. The next line public static string GetDataFromDB() shows one more error. I wrote you in my answer: "The web service should return object (not a string) which will be serialized by .NET framework to JSON string by usage of JavaScriptSerializer." Instead of the method GetDataFromDB return string instead of object. The returned string will be additionally serialized to XML or JSON. Thus you will have the same problem as before.
@Brian: If you will continue to use [WebMethod] then the results returned from GetDataFromDB will be always serialized using JavaScriptSerializer which is slow and have the size restriction which one can increase only by including maxJsonLength in the web.config. Only because the results will be serailized to JSON twice you require to use data: JSON.parse(data) parameter of jqGrid. The first deserializing from JSON makes $.ajax, but the result data.d is still string and not object (bacause of string GetDataFromDB() instead of object GetDataFromDB()).
@Brian: You can change public static string GetDataFromDB() to public static object GetDataFromDB() and change it's code to return ds.Tables[0]; instead of return JsonConvert.SerializeObject(ds.Tables[0]);. After that you can use data: data instead of data: JSON.parse(data). It would be the first step to clean you code. To solve your problem really you should don't use WebMethod at all. If you don't want/can to use more modern technologies then I recommend you to use at least ASHX handle which I referenced in my answer. Do you know how to add ASHX handle to existing project?
 
Oleg - moved to chat as suggested by SO. I'm putting this together from what I've seen on SO. I want to make it as modern as possible as this will be a production application. The standard gridview is crap, so I really need omething presentable.
I made your suggested changes to the method - return ds.Tables[0]; removed webmethod and changed the line in the function. Would rather not go the ASHX handle right now if there is an eaiser/better/more modern route. Sorry, but I'm stumped. Will mark as answered for all your trouble.
 
Short answer: If you want/have to use [WebMethod] then the returned data will be converted by JavaScriptSerializer and to fix the problem with the large data you will have to use MaxJsonLength settings in web.config.
 
6:24 PM
I don't have to use [WebMethod], nor do I want to since it has the issue with large data. I simply do not know how to write it to not use it. I will continue to research it. If you can point me to some examples, that would be great.
 
7:06 PM
Which version of Visual Studio you use? Do you create new project ofhave to support an old one?
 
2012 - new project.
 
7:37 PM
I would recommend you to use ASP.NET MVC
Later you can move to MVC6 in ASP.NET 5 which will be developed now by Microsoft as Open Source Project. ASP.NET MVC6 (currently exist in beta8, but RC1 will be published soon) seems to me the best choice for the future.
Because you use Visual Studio 2012 and not 2015 then you can just use ASP.NET MVC 5. See asp.net/mvc for many examples and tutorials.
In any way the choice of WebMethod now is the worst choice.
 
8:04 PM
Alternative could be to download Visual Studio Community version for free (from visualstudio.com/products/visual-studio-community-vs or go.microsoft.com/fwlink/?LinkId=532606) and follow the inctruction from docs.asp.net/en/latest/getting-started/… to use ASP.NET 5 and MVC6 now. In short time it will be final and you will be on the modern state of development.
The site docs.asp.net/en/latest and asp.net/vnext could get you good start.
The roadmap of ASP.NET 5 is here: github.com/aspnet/Home/wiki/Roadmap#schedule
ASP.NET 5 RC1 should be published Nov 2015 and release in Q1* 2016.
I don't know, which time sheduler you have for your project, but the usage of free Visual Studio Community version with free open source MVC6 and ASP.NET 5 could be a relaible option.
 
8:32 PM
I develop in Dot Net using a language called Visual RPG. It is a valid .Net language. I am limited to using VS2012 because of this. I've done smaller projects in C#, but nothing in MVC, with the exception of some tutorials in MVC 3 a couple years ago.
I used the Web application project since it had the membership functionality, and I spent a lot of time getting the tables onto my SQL server - 2018 R2. I actually don't remember if MVC gives me this, but I don't need CRUD for the grid - just a nicer alternative to Gridview - and the paging and sorting stuff I've seen with jqGrid is nice to have as well.
I don't have the time to scrap what I've done to learn MVC and then learn how to implememnt the jqGrid in it - again without using the [WebMethod].
I don't need the free version of VS 2015 as I have an MSDN subscrption - but according to what I have read, it cannot run on the same box as VS 2012
 
 
1 hour later…
9:36 PM
It's difficult to understand all your restrictions. Probably you can try to add ASHX to your project. Just select the project in Solution Explorer (on th right side), right mouse click to open context menu, choose "Add"/"New Item", then choose "Web" on the lest side and "Generic Handler" on the right side. You can choose the name of the file (Handler1.ashx) for example.
The method ProcessRequest is what you need to implement. You have HttpContext context as parameter and can use properties of methods of context.Response to implement any response from the URL.
You can use context.Response.ContentType = "application/json"; and context.Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate); at the beginning and use context.Response.Write(str); to write the string str which is JSON string of your data. You can use context.Response.Write(JsonConvert.SerializeObject(ds.Tables[0])); from your code.
See ProcessRequest from the answer stackoverflow.com/a/10871428/315935. You need just more simple version with the lines which I wrote before. The URL of jqGrid could be url: "Handler1.ashx" with path if required. It seems to me the most simple way with your existing restrictions. The code will be really simple.
 
9:54 PM
You can use IHttpAsyncHandler instead of IHttpHandler, but it's already details. In general *.ashx is almost the same as *.aspx, but *.ashx do not have a UI.
I can recommend you to read old weblog.west-wind.com/posts/2012/Sep/04/… where you find simple code which uses different technologies.
 

  last day (15 days later) »