views:

26

answers:

2

hi there

I have a little web app, that consumes a web service. the main page runs a search - by passing params to a particular ws method, and then i bind the results to a gridview.

I have implimented sorting and paging on the grid, by putting the datatable that the grid is bound to in the viewstate and then reading/sorting / filtering it when necessary - and rebinding to the grid.

recently - as the amount of data coming back from the WS has increased dramatically when i try to page/sort etc i get

The connection was reset

The connection to the server was reset while the page was loading.

having googled around a bit it seems that a very large viewstate is to blame for this. but surely the only other option is to

  1. Limit the results
  2. stick the datatable in the session rather than the viewstate
  3. dunno :)

previously i did have the datatable in the session, as some of this data needed to persist from page to page - (not being posted however so viewstate was not an option), but as the amount of data rose, and the neccessity to persist was removed, i used the viewstate instead. thinking this was a better option that the session anyway mostly because of the amount of data the session would have to hold, and the number of users using the app.

it appears maybe not

i actually thought that when the viewstate got very big, that .net split it over more than one hidden viewstate field, but it seems all im getting is one mamoth one that i have trouble viewing in the source..

can anyone enlighten me as to how to avoid the error im getting.. if it is indeed to do with the amount of data in the viewstate

many thanks

nat

+1  A: 

I wouldn't put the data in either the view state or the session. Instead store the bare minimum information to re-request the dataset from the web service and store that (in either view state or session, or even on the URL). Then call the web service using that data and reaction the data on each request. If necessary, look to use some form of caching (memCache) to improve performance.

Paul Hadfield
+1  A: 

It sounds like your caching the whole dataset for all pages even though you are only presenting one page of that data. I would change your pagination to only require the data for the current page the user is on.

If the query is heavy and you don't want to have to be constantly calling it over and over because there is a lot of paging back and forth (you should test typical useage pattern) then I would implement some type of caching on the web service end to cache page by page (by specific user if the data is specific to a user) and have it expire rather quick (eg a few minuites).

I think you need to limit the total amount of data your dealing with. Change your code to not pass back extra data that might never be needed is a good place to start.

EDIT: Based on your comments:

  1. You can't change the web service
  2. The user can manipulate the query by filtering or sorting
  3. There is a large amount of data returned by the web service
  4. The data is user specific

Well I think you have a perfect case for using the Session then. This can be taxing the the server with large amounts of users and data so you might want to implement some logic to clear the data from the Session and not wait for it to expire (like on certain landing pages you know the user will go when they are done, clear the session data).

You really want to get it out of the ViewState beacuse it is a huge bandwidth hog. Just look at your physical page size and that data is being passed back and forth with every action. Moving it to the Session would eliminate that bandwidth useage and allow for you to do everything you need.

You could also look at the data the web service is bringing back and store it in a custom object that you make as 'thin' as possible. If your storing a DataSet or a DataTable in your Session, those objects have some extra overhead you probably don't need so store the data as an array of some custom thin object and just bind to that. You would need to map the result from the WS to your custom object but this is a good option you cut down on memory useage.

Let me know if there is something else I am missing.

Kelsey
hi thanks for the replysurely in order to do that the WS would have to accept sort/page params.. basically handling the paging/sorting at the WS end, and requesting a pageworth of stuff at a time. but in order to do that, you would have to hold like you say a unique main search for each user who is logged on (we do have a session id passed with each WS request) and sort and page your way through that.this is never going to happen sadly. the WS are pretty much set in stone. so have to make do with what i have...continued in next comment
nat
continued..the client requires all the data coming back so that they can find what they want being lazy - ie not doing a very targetted search.. and filtering the grid to find what they want..there is a limit param passed to the initial large search, but setting that too low may make it impossible to find the record they are looking for.. as its may not be returned in the recordset from the WSany other ideas ?
nat
thanks again, your points are spot on, and i have switched back to the session and all is well.just have previously been poo pooed for using the session over the viewstate.. and of course i thought the viewstate was good, as if they leave their search page sitting there they can come back in 2 hrs and still filter/sort it (if the viewstate wasnt too big ofc) the session (if i dont want the server to grind to a halt) will have dropped their session in very much less than 2 hrs..thanks againnat
nat