Wednesday, July 04, 2007

Scenario: You have a Web application that is set to use cookieless sessions and want to call Web Services running in the same app domain and want to share the session state between the ASPX and the ASMX pages.

Problem: If you declare the Web Service path in the ScriptManager, the session ID will not be inserted automatically by AJAX or ASP.NET so when you'll call the Web Service, it will not be able to retrieve the session.

Solution: You need to use the Invoke method of the Sys.Net.WebServiceProxy object instead of declaring the WS in the ScriptManager section and you need to stuff the Session ID in the URL.  Just replace the JS line that call the Web method with one that use the Sys.Net.WebServiceProxy object Invoke method.
 
Sys.Net.WebServiceProxy.invoke('http://localhost/(S(<%=Session.SessionID %>))/SimpleService.asmx',
'SayHello', false,{}, OnComplete, OnError,"User Context",1000000);

More info about Sys.Net.WebServiceProxy.Invoke :
http://ajax.asp.net/docs/ClientReference/Sys.Net/WebServiceProxyClass/WebServiceProxyInvokeMethod.aspx

Wednesday, July 04, 2007 8:35:38 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 
All comments require the approval of the site owner before being displayed.
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):

Live Comment Preview

Theme design by Jelle Druyts