DCSIMG
Making Ajax calls to server using PageMethods and Session_End - Zuker On Foundations

Zuker On Foundations

The realm of .NET (WPF, WCF and all around)
Making Ajax calls to server using PageMethods and Session_End

We were working on a project where there was used the ajax pattern of PageMethods in order to call to the server.

We experienced a weird behavior where calling the operation marked as WebMethod (required to be called as part of the PageMethods) caused weird occurrences in the Session_End global event handler.

After dwelling into it, we found that the issue was solved once we enabled the session state in the WebMethod attribute.

I thought it might be worth sharing.

Published Thursday, January 15, 2009 3:25 PM by Amir Zuker

תגים:,

Comments

# re: Making Ajax calls to server using PageMethods and Session_End@ Sunday, January 18, 2009 8:18 AM

if i want to mark a function with the [WebMethod] it must be static?

and if it does, how should it recognize all the server controls on the webform?

shachar

# re: Making Ajax calls to server using PageMethods and Session_End@ Sunday, January 18, 2009 4:52 PM

Hi Shachar,

You can decorate a non-static operation with the [WebMethod] attribute.

However, In order to use the PageMethods pattern, you must set the operation as static. (The attribute itself doesn't require it, the PageMethods pattern does)

In this pattern it is usual that the operations are atomic stateless operations. That is receiving parameters from the client and returning a result upon it. (With the ability to access the SessionState obviously)

This pattern is not suitable for a case where you want the page to go through its entire life cycle and have control state loaded and all. In that case you should better use a callback.

Amir Zuker

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: