WCF service session is always NULL -


i have wcf service. in global.asax, put data asp.net session. when call wcf method, session object null.

this wcf service

[webmethod(enablesession = true)] public list<menu> getmenus() {             list<menu> menulist = new list<menu>();              object[] o = httpcontext.current.session["menu"] object[];              foreach (var item in o)             {                 menu menu = new menu();                 menu.html = ((wcfservices.menu)(item.totype(typeof(menu)))).html;                 menu.label = ((wcfservices.menu)(item.totype(typeof(menu)))).label;                 menulist.add(menu);             }              return menulist; }  [webinvoke(method = "get", responseformat = webmessageformat.json,                             requestformat = webmessageformat.json,                             bodystyle = webmessagebodystyle.wrappedrequest)] list<menu> getmenus(); 

here global.asax file

protected void session_start(object sender, eventargs e) {      crmhelper helper = new crmhelper();       if (session["service"] == null)      {          iorganizationservice s = helper.createservice(true);          session["service"] = s;      }       mobilehelper mobilehelper = new mobilehelper((iorganizationservice)session["service"]);      if (session["menu"] == null)      {          session["menu"] = mobilehelper.getmainmenus();      } } 

accessing session["service"] or session["menu"] returns null when call wcf service.

any ideas?

the main issue is: wcf not asp.net !

by default, wcf not rely on asp.net runtime (and that's good thing!!) , doesn't have access asp.net constructs session ...

if need provide data wcf service, best place put info database table wcf service can load information from.

if insist on using asp.net session storage, , don't mind you're limiting using only iis asp.net hosting environment wcf service in case, check out blog post showing need gain access asp.net session state.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -