Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, April 14, 2009 12:24 PM
In my web service I need to keep track of a value called store number. I have two methods I use to attempt to do this. Both have EnableSession=true set.
Method #1 - SetStoreNbr(string StoreNum) - I call this method and pass it the value. The value is then stored in the Session variable, like this:
Session["StoreNum"] = StoreNum;
In method #2 - GetStoreNbr(), I attempt to retrieve the value from the Session variable, like so:
string str = Session["StoreNum"].ToString();
However, when GetStoreNbr() is called, the Session variable is null, resulting in the following error:
System.Web.Services.Protocols.SoapException: Server was unable to process request.
> System.NullReferenceException: Object reference not set to an instance of an object.
at THDEMPWebS.GetStoreNbr()
If I execute the Web Service in the browser via the asmx file, I can execute both of these of methods just fine. GetStoreNbr() will return me the store number. Attempting to execute these methods through an ASP.NET application raises the error mentioned above.
I'm new to ASP.NET, so if there's a better way to do this, please feel free to mention it.
Thanks.
All replies (5)
Friday, April 17, 2009 2:29 AM ✅Answered
Hi,
You can try session mode "StateServer" which needs start the "StateServer" in server.
1. Deploy the sessionState in web.config as:
<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="600"/>
2. Before starting web application, you need start StateServer Service.(Administration Tools-> Services->ASP.NET State Service->Start)
This link can lead you to know about Session State with StateServe and SqlServer:
http://wixuser.blogspot.com/2007/11/session-state-with-sqlserver-or_09.html
Friday, April 17, 2009 3:01 AM ✅Answered
In your Method#1 just check whether you are able to set the value of StoreNum to session variable.
in your web config
<add namespace="System.Web.SessionState"/>
<sessionState mode="InProc"></sessionState>
Regards
Asif
Tuesday, April 14, 2009 1:31 PM
On your [WebMethod] attribute you should add EnableSession=true
Like that:
[WebMethod(EnableSession=true)]
Tuesday, April 14, 2009 4:23 PM
Thanks, that's how I've had it coded, and it didn't work.
I managed to fix the problem by switching to "Application" instead of Session, but if anyone knows why Session doesn't work that would be nice.
Thursday, July 12, 2012 9:55 AM
[WebMethod(EnableSession=true)]
Working Fine, Thanks.