Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
In my web service I need to get one value from session variable. In the constructor of my web service I am getting this value like
 

constructor()  // constructor of web service
{
  Person p = (Person)Session["xyz"];
  string name = p.Name;
  string Address = p.Address
}
 
my java script is like bellow
 
function CallWebservice()
{
MyWebservice.GetValueFromDb(onsucess,onfailure)
}

It works perfectly fine but some time i got the session as null, i have the session state in web.config which has default time out as 60 minutes.
 
but before 60 minutes(not all the time) the session is getting null, this things happens only when i am calling the webservice from java script
Posted 13-Feb-13 2:14am
nil1385261
Edited 13-Feb-13 2:35am
joe_j4K
v3
Comments
ryanb31 at 13-Feb-13 9:42am
   
Do you have [WebMethod(EnableSession = true)] on your webmethod?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Im agreed with ryanb31 answer.
First you have to enable the session in your web service.
you can do that by adding following line to your web service
[WebMethod(EnableSession = true)]
 
http://msdn.microsoft.com/en-us/library/aa480509.aspx[^]
http://msdn.microsoft.com/en-us/library/system.web.services.webmethodattribute.enablesession(v=vs.90).aspx[^]
 
and avoid the session time out, you can create a non functional web service and keep calling to it using the javascript setInterval method.
[WebMethod(true)]
        public void KeepAlive()
        {
            //do nothing
        }
//to keep the session alive
window.setInterval(function(){
  //call KeepAlive web service 
}, 60000);
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100