Wednesday, March 28, 2012

Ajax Beta WebService with Sessions

Hello all, I need help here. I have a little app that requires getting the session within a webservice. I can't seem to access the session object. Here is my little webservice:

[WebMethod (EnableSession =true)]

[ScriptMethod]

publicstaticArrayList getProductsData()

{

return (ArrayList)Session["productsAL"];

}

Here is my call to the service:

[Microsoft.Web.Script.Services.ScriptMethod]

publicstaticint GetProductCount()

{

returnQuickShipService.getProductsCount();

}

I'm getting a compilation error. With this setup I get the error

Error 1 An object reference is required for the nonstatic field, method, or property 'System.Web.Services.WebService.Session.get' C:\Projects\TMR\POSOrdering\POSWWW\App_Code\Retail\QuickShipService.cs 31 27 C:\...\POSWWW\

It compiles if I remove the static keyword from the service, but then the webservice callreturnQuickShipService.getProductsCount(); is invalid.

Thanks f

or

your method is static, try

return (ArrayList)HttpContext.Current.Session["productsAL"];

No comments:

Post a Comment