Atlas and the page methods

Published 12 May 06 11:22 AM | despos

At DevConnections, I presented a session entitled "The Atlas Framework--The Big Picture" where I first explained the background of the Ajax lifestyle and the motivation for Atlas. I then finished off presenting a couple of examples--how to call a Web service from an Atlas page and how to invoke a page method.

It is interesting to see how page methods work internally.

A page method is an inline method decorated with the [WebMethod] attribute and placed inside a server-side script block of type C#/VB.

 <script type="text/C#" runat="server">
   [WebMethod]
   public string RetrieveMoreInfo(string id) 
   {
       return RetrieveMoreInfoInternal(id);
   }
</script>

To invoke this method from the client, you need the following Javascript code:

function GetMoreInfo() 
{
    PageMethods.RetrieveMoreInfo(
            document.getElementById('cboEmployees').value,      
            OnComplete, 
          
 null);

    return false;
}

What's the PageMethods object? And who created that? PageMethods is a Javascript object declared in the HTML source. The Atlas server-side framework provides for the following code. To see this code, you just open the View Source window of your browser when the Atlas page is displayed.

<script type="text/javascript">
var PageMethods = new function() {
   var cm=Web.Net.PageMethodRequest.createProxyMethod;
   cm(this,"RetrieveMoreInfo","id");
}
</script>

When the user triggers the above GetMoreInfo Javascript function, the HTTP request contains a couple of extra input fields added by proxy method. They are __serviceMethodName and __serviceMethodParams. Here's a typical request:

POST /Atlas/Postback.aspx HTTP/1.1
Cache-Control: no-cache
Connection: Keep-Alive
Content-Length: 478
Content-Type: application/x-www-form-urlencoded
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: en-us,it;q=0.5
Cookie: .ASPXANONYMOUS=M ... s1
Host: localhost:2471
Referer:
http://localhost:2471/Atlas/Postback.aspx
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Avalon 6.0.5070; WinFX RunTime 3.0.50727)
UA-CPU: x86

__serviceMethodName=RetrieveMoreInfo&
__serviceMethodParams={"id":"5"}&
__VIEWSTATE=/wEPDw ... EtV

This request is intercepted by an Atlas-specific HTTP module, named ScriptModule. The HTTP module kicks in immediately after the handler for the request has been found. If this handler is a Page class--that is, the request is directed to a page (as opposed to a Web service)--the HTTP module registers its own handler for the PreRenderComplete event.
In turn, the PreRenderComplete event code registers a render method delegate (a custom piece of code that runs during the Render method). This code retrieves the method name and parameters, does any due deserialization, and invokes the page method via reflection.

Everything else works just as usual.

NOTE: These details may change in future builds of Atlas

Comments

# Ulli said on May 12, 2006 06:30 AM:

This is something we are already using with the Ajax.NET library from Michael Schwarz, Germany, since one year. It allows you to use any argument and return value, there is a big support on common data types like DataSet or DataTable and List<T>. Have a look at his web page at http://www.ajaxpro.info/default.aspx.

# Bernd said on May 12, 2006 08:32 AM:

Ulli, yes, it seems to be the same way as Ajax.NET. I tried already to get it working but the data type support is very bad, seems to be not finished to work. Do you have tested the ajax.net lib in details?s

# Jeff Modzel said on May 12, 2006 02:53 PM:

Dino - your contact page is broken. Get a message saying that the mail server can't send.

# cyril said on May 12, 2006 07:38 PM:

Can we now what would change ? is it a big change or just a small one ?

# Rick Strahl said on May 13, 2006 04:54 PM:

Uli, the same stuff works with ATLAS too and a number of other AJAX tools. The JSON() / PageMethod type callback support is pretty much common AJAX fare these days.

What's interesting about ATLAS is that it supports two mechanisms for this. One is PageMethods as Dino describes above, the other is the Web Service functionality which is actually very different and uses pure JSON to the server. The difference is that PageMethods can participate in the Page cycle so they get ViewState and POST data, whereas WebMethods to a Web Service are raw service calls with JSON up and down - which is much more efficient and generally - IMHO - a much better approach as it forces you to think of the result returned as 'Data' by talking to a Service.

PageMethods may change in the format that goes over the wire. Shouldn't drastically affect the behavior of the client or server code though. One feature I've heard mumblings about is to allow PageMethods to act like WebService methods in that no POST/ViewState data is sent using a special Attribute flag or the static/shared keyword.

# Xanax said on May 15, 2006 08:43 PM:

Hi, all! 8 Since 'being' in general has several senses, of which one is'being by accident', we must consider first that which 'is' in thissense.

# blogs-yzdx said on May 16, 2006 10:59 AM:

Visit http://www.ezheat.com/rachel/?Patanol/ http://www.ezheat.com/rachel/?Effexor-XR/ http://www.ezheat.com/rachel/?Fluoxetine/ http://www.ezheat.com/rachel/?Lexapro/ http://www.ezheat.com/rachel/?Paxil-CR/ http://www.ezheat.com/rachel/?Albenza/ http://www.ezheat.com/rachel/?Elimite/ http://www.ezheat.com/rachel/?Eurax/ http://www.ezheat.com/rachel/?Vermox/ http://www.ezheat.com/rachel/?Zithromax/ http://www.ezheat.com/rachel/?Colchicine/ http://www.ezheat.com/rachel/?Zyloprim/ http://www.ezheat.com/rachel/?Mircette/ http://www.ezheat.com/rachel/?Triphasil/ http://www.ezheat.com/rachel/?Aldactone/ http://www.ezheat.com/rachel/?Esgic-Plus/ http://www.ezheat.com/rachel/?Bentyl/ http://www.ezheat.com/rachel/?Ranitidine-HCL/ http://www.ezheat.com/rachel/?Antivert/ http://www.ezheat.com/rachel/?Transderm-Scop/

# xanax said on May 19, 2006 01:56 PM:

Nice design. And (c) thematter of each thing, and therefore of substance, must be that whichis potentially of the nature in question; but the relative isneither potentially nor actually substance.

# xanax said on May 19, 2006 01:56 PM:

Good site. This we have saidalready.

# xanax said on May 19, 2006 01:56 PM:

Good site. And perhaps if one had questioned Heraclitushimself in this way one might have forced him to confess that oppositestatements can never be true of the same subjects.

# xanax said on May 19, 2006 01:56 PM:

Cool design, but very light. This is why the same seed becomes female or male by beingacted on in a certain way.

# xanax said on May 19, 2006 01:57 PM:

Cool design, but very light. the unequal), which isneither the contrary nor the contradictory of these, and is one kindof being as 'what' and quality also are.

# xanax said on May 19, 2006 01:57 PM:

Cool design, but very light. But as for him who does not hold this view because hesees the inherent objections to the Ideas (so that it is not forthis reason that he posits numbers), but who posits mathematicalnumber, why must we believe his statement that such number exists, andof what use is such number to other things? Neither does he who saysit exists maintain that it is the cause of anything (he rather says itis a thing existing by itself), nor is it observed to be the causeof anything; for the theorems of arithmeticians will all be found trueeven of sensible things, as was said before.

# xanax said on May 19, 2006 01:57 PM:

Hi, all!These are the thingswhose nature remains the same after transposition, but whose form doesnot, e.g.

# xanax said on May 19, 2006 01:57 PM:

Good site. If they are a man, a horse, and a god, the measure is perhaps'living being', and the number of them will be a number of livingbeings.

# xanax said on May 19, 2006 01:57 PM:

Nice site. For the cause of the formeris indeterminate, and that of the latter is some affection of thethought, and both are related to the remaining genus of being, anddo not indicate the existence of any separate class of being.Therefore let these be dismissed, and let us consider the causes andthe principles of being itself, qua being.

# xanax said on May 21, 2006 12:42 AM:

Nice design. Yet the acquisition of it must in a sense end in something whichis the opposite of our original inquiries.

# xanax said on May 21, 2006 12:42 AM:

Hi, all!For it is owing to theirwonder that men both now begin and at first began to philosophize;they wondered originally at the obvious difficulties, then advancedlittle by little and stated difficulties about the greater matters,e.g.

# xanax said on May 21, 2006 12:42 AM:

Hi, all!But the divine power cannot be jealous (nay,according to the proverb, 'bards tell a lie'), nor should any otherscience be thought more honourable than one of this sort.

# xanax said on May 21, 2006 12:42 AM:

Cool design, but very light. why fire is hot; they onlysay that it is hot.

# xanax said on May 21, 2006 12:42 AM:

Nice site. For not only with a view to action, but even when we are notgoing to do anything, we prefer seeing (one might say) to everythingelse.

# xanax said on May 21, 2006 12:42 AM:

Good site. And to seek this is to seek the secondcause, as we should say,-that from which comes the beginning of themovement.

# xanax said on May 21, 2006 12:42 AM:

Good site. about the phenomena of the moon and those of the sun and of thestars, and about the genesis of the universe.

# xanax said on May 21, 2006 12:43 AM:

Hi. And ingeneral it is a sign of the man who knows and of the man who doesnot know, that the former can teach, and therefore we think art moretruly knowledge than experience is; for artists can teach, and menof mere experience cannot.

# xanax said on May 21, 2006 12:43 AM:

Hi, all!Hence when all such inventionswere already established, the sciences which do not aim at givingpleasure or at the necessities of life were discovered, and first inthe places where men first began to have leisure.

# Cyril 's Blog said on May 22, 2006 07:14 PM:

Une des fonctionnalit&#233;s int&#233;ressante d'Atlas est de pouvoir tr&#232;s facilement appeler des m&#233;thodes de WebService...

# Cyril 's Blog said on May 22, 2006 07:15 PM:


Une des fonctionnalit&#233;s int&#233;ressante d'Atlas est de pouvoir tr&#232;s facilement appeler des m&#233;thodes de...

# Rose,Rose said on June 16, 2007 07:27 AM:

Hi there! Just couldn't resist your guestbook! Please also visit my site:

# ctl00$main$ctl09$ctl02$ctl02$ctl02$tbname said on July 11, 2007 10:07 AM:

paroxetine effexor <a href= http://effexor.beeplog.de >interaction effexor</a> [url=http://effexor.beeplog.de]interaction effexor[/url]

# ctl00$main$ctl08$ctl02$ctl02$ctl02$tbname said on January 4, 2008 03:38 PM:

comparison effexor <a href= effexor.1fr1.com/.../Effexor-Effexor-Effexor-xr-b1-p2.htm >actos effexor</a> [url=effexor.1fr1.com/.../Effexor-Effexor-Effexor-xr-b1-p2.htm]actos effexor[/url]

# ctl00$main$ctl08$ctl02$ctl02$ctl02$tbname said on June 12, 2008 12:02 PM:

антимаулнетизм качественно <a href= http://antiprivichka.ru >с антимаулнетизм</a> [url=http://antiprivichka.ru]с антимаулнетизм[/url]

Leave a Comment

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