<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" version="2.0">
  <channel>
    <title>Manuel Abadia's ASP.NET stuff - Ajax</title>
    <link>http://www.manuelabadia.com/blog/</link>
    <description />
    <language>en-us</language>
    <copyright>Manuel Abadia</copyright>
    <lastBuildDate>Sun, 10 Jun 2007 16:59:18 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.9.6264.0</generator>
    <managingEditor>blogcomments@manuelabadia.com</managingEditor>
    <webMaster>blogcomments@manuelabadia.com</webMaster>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=31a01aba-565d-46ab-b8af-bde3352905c9</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,31a01aba-565d-46ab-b8af-bde3352905c9.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,31a01aba-565d-46ab-b8af-bde3352905c9.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=31a01aba-565d-46ab-b8af-bde3352905c9</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In previous posts about MS AJAX, we have been studying the new elements introduced
in the web.config for a new project that uses Microsoft ASP.NET AJAX Extensions. The
last thing we have to study is the ScriptModule HttpModule:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;</span>
            <span style="COLOR: #a31515">httpModules</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">      &lt;</span>
            <span style="COLOR: #a31515">add</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">name</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">ScriptModule</span>"<span style="COLOR: blue"></span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>"<span style="COLOR: blue">/&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;/</span>
            <span style="COLOR: #a31515">httpModules</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
        </div>
        <p>
          <!--EndFragment-->
          <br />
The ScriptModule is necessary to provide 3 features needed by the MS AJAX:
</p>
        <blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
          <p>
• To allow page redirection in a partial page update.<br />
• To be able to call page methods instead of web service methods.<br />
• To serve some files to the users skipping the standard authorization mechanism.
</p>
        </blockquote>
        <p>
          <br />
Let’s see how those features are implemented. The ScriptModule handles three HttpApplication
events:
</p>
        <blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
          <p>
• PreSendRequestHeaders<br />
• PostAcquireRequestState<br />
• AuthenticateRequest
</p>
        </blockquote>
        <p>
          <br />
The PreSendRequestHeaders event is raised before the server sends the headers to the
browser, and it is the last chance to modify them. The ScriptModule handles this event,
and checks if the current response code is 302, emitted when you call to the Response.Redirect
method. 
</p>
        <p>
          <br />
As we will see when we study the UpdatePanel, it allows partial page updates, generating
XMLHttp requests. A partial page update has a request header of type "X-MicrosoftAjax"
with a value of “Delta=true”. However, as the response of this request is handled
internally by the MS AJAX runtime instead of the browser, the redirect wasn’t working.
The ScriptModule fixes this problem, because when a redirect is found for a partial
page update request, it clears the response (headers and content), maintaining the
cookie collection and returning a string as the content of the response. The content
of the response is obtained by calling the EncodeString method of an internal class
called PageRequestManager. This class plays a key role in the MS AJAX infrastructure
and will be studied in detail in future posts. For now, we’re only interested in the
EncodeString method, that has 3 main parameters (type, id and content) and generates
a string that looks like this:
</p>
        <p>
          <em>Length + ‘|’ + type + ‘|’ + id + ‘|’ + content + ‘|’</em>
        </p>
        <p>
Encoding the characters “\u0000” and “\u00ff”.
</p>
        <p>
In the client side, when the response has been received, the _onFormSubmitCompleted
method of the PageRequestManager class checks the type of command specified, and acts
accordingly.
</p>
        <p>
When a redirect is found in response for a partial page update, the ScriptModule generates
a string of type “pageRedirect”, where the redirect location is stored in the content.
The client side handles this command as shown below:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">case</span>
            <span style="COLOR: #a31515">"pageRedirect"</span>:
</p>
          <p style="MARGIN: 0px">
    window.location.href = deltaNode.content;
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">return</span>;
</p>
        </div>
        <p>
          <!--EndFragment-->
          <br />
making the redirect work as expected.<br /></p>
        <p>
One thing to point is that the ScriptModule checks if a rest call has generated a
redirect, throwing and exception in that case. This is done for security reasons.
</p>
        <p>
The PostAcquireRequestState event is raised after the session data has been obtained.
If the request is for a class that implements System.Web.UI.Page and it is a rest
method call, the WebServiceData class (that was explained in a previous post) is used
to call the requested method from the Page. After the method has been called, the
CompleteRequest method is called, bypassing all pipeline events and executing the
EndRequest method. This allows MS AJAX to be able to call a method on a page instead
of having to create a web service to call a method.
</p>
        <p>
The AuthenticateRequest event is raised after the identity of the current user has
been established. The handler for this event sets the SkipAuthorization property of
the HttpContext for the current request. This property is checked in the authorization
module to see if it has to omit authorization checking for the requested url. Usually
an HttpModule use this property to allow anonymous access to some resources (for example,
the Login Page if we’re using forms authentication). In our scenario, the ScriptModule
sets the SkipAuthorization to true if the requested url is scriptresource.axd or if
the authorization module is enabled and the request is a rest request to the authorization
web service.
</p>
        <p>
As you can see, the ScriptModule isn’t terribly complicated but it is necessary to
have the MS AJAX infrastructure working properly.
</p>
        <p>
If we check the AJAX ASP.NET Extensions server side source code, we have now studied
about a 33% of it and we haven’t done anything more than study the new infrastructure
elements provided for a MS AJAX application in the web.config. The most interesting
stuff is to come.
</p>
        <p>
In the next posts I’ll talk about the ScriptManager control.
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=31a01aba-565d-46ab-b8af-bde3352905c9" />
      </body>
      <title>ASP.NET AJAX Extensions Internals - ScriptModule</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,31a01aba-565d-46ab-b8af-bde3352905c9.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,31a01aba-565d-46ab-b8af-bde3352905c9.aspx</link>
      <pubDate>Sun, 10 Jun 2007 16:59:18 GMT</pubDate>
      <description>&lt;p&gt;
In previous posts about MS AJAX, we have been studying the new elements introduced
in the web.config for a new project that uses Microsoft ASP.NET AJAX Extensions. The
last thing we have to study is the ScriptModule HttpModule:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;httpModules&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;add&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;ScriptModule&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;httpModules&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;br&gt;
The ScriptModule is necessary to provide 3 features needed by the MS AJAX:
&lt;/p&gt;
&lt;blockquote dir=ltr style="MARGIN-RIGHT: 0px"&gt; 
&lt;p&gt;
•&amp;nbsp;To allow page redirection in a partial page update.&lt;br&gt;
•&amp;nbsp;To be able to call page methods instead of web service methods.&lt;br&gt;
•&amp;nbsp;To serve some files to the users skipping the standard authorization mechanism.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;br&gt;
Let’s see how those features are implemented. The ScriptModule handles three HttpApplication
events:
&lt;/p&gt;
&lt;blockquote dir=ltr style="MARGIN-RIGHT: 0px"&gt; 
&lt;p&gt;
•&amp;nbsp;PreSendRequestHeaders&lt;br&gt;
•&amp;nbsp;PostAcquireRequestState&lt;br&gt;
•&amp;nbsp;AuthenticateRequest
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;br&gt;
The PreSendRequestHeaders event is raised before the server sends the headers to the
browser, and it is the last chance to modify them. The ScriptModule handles this event,
and checks if the current response code is 302, emitted when you call to the Response.Redirect
method. 
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
As we will see when we study the UpdatePanel, it allows partial page updates, generating
XMLHttp requests. A partial page update has a request header of type "X-MicrosoftAjax"
with a value of “Delta=true”. However, as the response of this request is handled
internally by the MS AJAX runtime instead of the browser, the redirect wasn’t working.
The ScriptModule fixes this problem, because when a redirect is found for a partial
page update request, it clears the response (headers and content), maintaining the
cookie collection and returning a string as the content of the response. The content
of the response is obtained by calling the EncodeString method of an internal class
called PageRequestManager. This class plays a key role in the MS AJAX infrastructure
and will be studied in detail in future posts. For now, we’re only interested in the
EncodeString method, that has 3 main parameters (type, id and content) and generates
a string that looks like this:
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;Length + ‘|’ + type + ‘|’ + id + ‘|’ + content + ‘|’&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
Encoding the characters “\u0000” and “\u00ff”.
&lt;/p&gt;
&lt;p&gt;
In the client side, when the response has been received, the _onFormSubmitCompleted
method of the PageRequestManager class checks the type of command specified, and acts
accordingly.
&lt;/p&gt;
&lt;p&gt;
When a redirect is found in response for a partial page update, the ScriptModule generates
a string of type “pageRedirect”, where the redirect location is stored in the content.
The client side handles this command as shown below:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;case&lt;/span&gt; &lt;span style="COLOR: #a31515"&gt;"pageRedirect"&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; window.location.href = deltaNode.content;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt;;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;br&gt;
making the redirect work as expected.&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
One thing to point is that the ScriptModule checks if a rest call has generated a
redirect, throwing and exception in that case. This is done for security reasons.
&lt;/p&gt;
&lt;p&gt;
The PostAcquireRequestState event is raised after the session data has been obtained.
If the request is for a class that implements System.Web.UI.Page and it is a rest
method call, the WebServiceData class (that was explained in a previous post) is used
to call the requested method from the Page. After the method has been called, the
CompleteRequest method is called, bypassing all pipeline events and executing the
EndRequest method. This allows MS AJAX to be able to call a method on a page instead
of having to create a web service to call a method.
&lt;/p&gt;
&lt;p&gt;
The AuthenticateRequest event is raised after the identity of the current user has
been established. The handler for this event sets the SkipAuthorization property of
the HttpContext for the current request. This property is checked in the authorization
module to see if it has to omit authorization checking for the requested url. Usually
an HttpModule use this property to allow anonymous access to some resources (for example,
the Login Page if we’re using forms authentication). In our scenario, the ScriptModule
sets the SkipAuthorization to true if the requested url is scriptresource.axd or if
the authorization module is enabled and the request is a rest request to the authorization
web service.
&lt;/p&gt;
&lt;p&gt;
As you can see, the ScriptModule isn’t terribly complicated but it is necessary to
have the MS AJAX infrastructure working properly.
&lt;/p&gt;
&lt;p&gt;
If we check the AJAX ASP.NET Extensions server side source code, we have now studied
about a 33% of it and we haven’t done anything more than study the new infrastructure
elements provided for a MS AJAX application in the web.config. The most interesting
stuff is to come.
&lt;/p&gt;
&lt;p&gt;
In the next posts I’ll talk about the ScriptManager control.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=31a01aba-565d-46ab-b8af-bde3352905c9" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,31a01aba-565d-46ab-b8af-bde3352905c9.aspx</comments>
      <category>Ajax;ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=7d51552e-e524-48a5-a079-761c6ee24020</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,7d51552e-e524-48a5-a079-761c6ee24020.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,7d51552e-e524-48a5-a079-761c6ee24020.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=7d51552e-e524-48a5-a079-761c6ee24020</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <strong>Where were we?</strong>
        </p>
        <p>
In my previous posts about MS AJAX Extensions I talked about the additions to the
web.config, Serialization, proxy generation, and ScriptHandlerFactory, that is the
factory that handles *.asmx requests and *_AppService.axd requests. To refresh memory,
what the ScriptHandlerFactory does is to check if the request has application/json
ContentType (a REST method request) or the request path ends with /js or /jsdebug
(a REST client proxy request). If it is a REST method request (<u><font color="#0000ff">http://localhost/AJAXServerSide1/AjaxWebService.asmx/GetModifiedUser</font></u>),
it gets the web service data, calls the requested method and returns the result. If
it is a REST client proxy request (<font color="#0000ff"><u>http://localhost/AJAXServerSide1/AjaxWebService.asmx/js</u></font>),
it returns the generated client proxy. If it isn’t a REST method request or a REST
client proxy request, it delegates the request to the “normal” *.asmx HttpHandler.
</p>
        <p>
The  HttpHandler for *_AppService.axd exists to allow the developer to use some
application services with AJAX. The only available application services available
in v1.0 are Profile_JSON_AppService.axd and Authentication_JSON_AppService.axd. The
profile service exposes the methods: 
</p>
        <blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
          <p>
• GetAllPropertiesForCurrentUser<br />
• GetPropertiesForCurrentUser<br />
•  SetPropertiesForCurrentUser. 
</p>
        </blockquote>
        <p>
The authentication service exposes the following methods:
</p>
        <blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
          <p>
• Login<br />
• Logout
</p>
        </blockquote>
        <p>
To use the services, we have to enable them in the web.config. For the profile service,
we have to set the properties that can be read and write by MS AJAX. For the authentication
service we can specify if it requires SSL or not.
</p>
        <p>
There is a role service that exposes the method GetRolesForUser but it isn’t enabled
in the current version.<br />
The default implementation of the services can be changed, but I won’t be touching
that until we study the ScriptManager.
</p>
        <p>
The last HttpHandler that MS AJAX adds to the web.config is the ScriptResourceHandler,
for the path ScriptResource.axd. Lets study it in more detail…
</p>
        <p>
          <strong>ScriptResourceHandler in detail</strong>
        </p>
        <p>
The main function performed by the ScriptResourceHandler is to load scripts from resources
stored in the assembly and adding localized resources to the scripts.
</p>
        <p>
A request to the ScriptResource.axd must be done at the root level for the application
(~/ScriptResource.axd). The request has the information needed to process it encrypted
in the query string (the encryption and decryption process is done using the EncryptString
and DecryptString methods of the System.Web.UI.Page class). The decrypted format for
the query string is:
</p>
        <p>
          <em>“d=” + 1 character that indicates additional processing + assembly name + ‘|’
+ resource name + ‘|’ + cultureName.</em>
        </p>
        <p>
          <br />
The first character can be ‘u’, ‘U’, ‘z’ or ‘Z’. An uppercase character indicates
that the feature is enabled and the lowercase character indicates that the feature
is disabled. The ‘Z’ indicates that the resource has to be compressed (using GZip).
The ‘U’ indicates to add some code to the end of the script, to notify the MS AJAX
runtime that script has been loaded. The code that gets added to the script is:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span>(<span style="COLOR: blue">typeof</span>(Sys)!==<span style="COLOR: #a31515">'undefined'</span>)Sys.Application.notifyScriptLoaded();
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
The assembly name and the resource name must be specified. If not, an error 404 (page
not found) will be returned. The culture name is used to set the CurrentThead.CurrentUICulture
property. If no culture is specified, the invariant culture is used.
</p>
        <p>
To expose resources stored in an assembly, the assembly level attributes ScriptResourceAttribute
and WebResourceAttribute have to be used.
</p>
        <p>
The ScriptResourceAttribute has 3 important properties: ScriptName, ScriptResourceName
and TypeName. The ScriptName property will be compared to the requested resource name.
ScriptResourceName points to a resource file that contains strings. The TypeName property
specifies a script type that will be created containing the localized strings (of
the CurrentUICulture, or the default ones if no CurrentUICulture specific resources
exist) present in the resource specified by ScriptResourceName.
</p>
        <p>
The WebResourceAttribute has 3 important properties: WebResource, ContentType and
PerformSubstitution. The WebResource property will be compared to the requested resource.
ContentType specifies the type of data stored in the resource and will be used to
write the ContentType for the response. The PerformSubstitution property is used by
the ScriptResourceHandler in order to convert expressions like:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
&lt;%= WebResource(<span style="COLOR: #a31515">"MyResources.JScript2.js"</span>)
%&gt; or &lt;%= ScriptResource(<span style="COLOR: #a31515">"MyResources.JScript2.js"</span>)
%&gt;
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
To the URL of the resource. If WebResource is used, the generated URL will start with
“WebResource.axd?d=”. For ScriptResource, the generated URL will start with “ScriptResource.axd?d=”.
The substitution is performed using regular expressions.
</p>
        <p>
When a resource in an assembly is requested, the assembly is inspected for the assembly
level attributes ScriptResourceAttribute and WebResourceAttribute. Information about
the requested resource is stored in the class ScriptResourceInfo, that has the properties
of ScriptResourceAttribute and WebResourceAttribute combined. For the same resource
name, we can have a ScriptResourceAttribute and a WebResourceAttribute. If only ScriptResourceAttribute
is specified, the default content type is "application/x-javascript". The ScriptResourceInfo
is cached using the assembly and resource name as the cache key.
</p>
        <p>
When a resource that ends with .debug.js is requested, the release mode resource (resource
name that ends with .js) is also requested. At least one of those resources has to
exist.
</p>
        <p>
If we have set the property EnableCaching for the ScriptResourceHandler in the configuration
section, the response will be cached using the ASP.NET output cache by the server
for a year.
</p>
        <p>
The response will be generated in 3 steps:
</p>
        <blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
          <p>
• The requested resource will be read using the GetManifestResourceStream method
from the Assembly class.  If PerformSubstitution is enabled, the substitution
explained above is performed.<br />
• If the ScriptResourceAttribute is used, a ResourceManager for the resource
file with the localized resources is obtained, and some script is added to save the
resources (see the code below)<br />
• If the MS AJAX runtime has to be notified of the loading of the script, add
the script line shown above.
</p>
        </blockquote>
        <p>
          <strong>Example</strong>
        </p>
        <p>
If we have the following assembly level attributes:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
[assembly: <span style="COLOR: #2b91af">ScriptResource</span>(<span style="COLOR: #a31515">"MyResources.JScript1.js"</span>, <span style="COLOR: #a31515">"MyResources.MyStrings"</span>, <span style="COLOR: #a31515">"MyResources.Res"</span>)]
</p>
          <p style="MARGIN: 0px">
[assembly: <span style="COLOR: #2b91af">WebResource</span>(<span style="COLOR: #a31515">"MyResources.JScript1.js"</span>, <span style="COLOR: #a31515">"application/x-javascript"</span>,
PerformSubstitution=<span style="COLOR: blue">true</span>)]
</p>
          <p style="MARGIN: 0px">
[assembly: <span style="COLOR: #2b91af">WebResource</span>(<span style="COLOR: #a31515">"MyResources.JScript2.js"</span>, <span style="COLOR: #a31515">"application/x-javascript"</span>)]
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
The file MyResources.JScript1.js is like this:<br /></p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//jscript1</span>
          </p>
          <p style="MARGIN: 0px">
&lt;%= WebResource(<span style="COLOR: #a31515">"MyResources.JScript2.js"</span>)
%&gt;
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
The file MyStrings.resx has the string named String1 = “This is a test”, when the
resource “MyResources.JScript1.js” is requested, the response content is:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//jscript1</span>
          </p>
          <p style="MARGIN: 0px">
WebResource.axd?d=aGTLuR-3gZaSvlaJzlNqJOqXDQAwO3kOV34svo62fA708VHtJJ6R4HtCd41V1jZv0&amp;t=633164083963984167
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
Type.registerNamespace(<span style="COLOR: #a31515">'MyResources'</span>);
</p>
          <p style="MARGIN: 0px">
MyResources.Res={
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #a31515">"String1"</span>:<span style="COLOR: #a31515">"This is
a test!"</span></p>
          <p style="MARGIN: 0px">
};
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span>(<span style="COLOR: blue">typeof</span>(Sys)!==<span style="COLOR: #a31515">'undefined'</span>)Sys.Application.notifyScriptLoaded();
</p>
        </div>
        <p>
          <!--EndFragment-->If you add another resource file to localize the resources for spanish
(MyStrings.es-ES.resx) and configure the application to use the Spanish UI culture,
the response for the resource “MyResources.JScript1.js” is:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: green">//jscript1</span>
          </p>
          <p style="MARGIN: 0px">
WebResource.axd?d=aGTLuR-3gZaSvlaJzlNqJOqXDQAwO3kOV34svo62fA708VHtJJ6R4HtCd41V1jZv0&amp;t=633164083963984167
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
Type.registerNamespace(<span style="COLOR: #a31515">'MyResources'</span>);
</p>
          <p style="MARGIN: 0px">
MyResources.Res={
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #a31515">"String1"</span>:<span style="COLOR: #a31515">"¡Esto
es una prueba!"</span></p>
          <p style="MARGIN: 0px">
};
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span>(<span style="COLOR: blue">typeof</span>(Sys)!==<span style="COLOR: #a31515">'undefined'</span>)Sys.Application.notifyScriptLoaded();
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
That's all for now. In a next post I'll finally finish explaining all the elements
present in the web.config for an asp.net ajax application.
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=7d51552e-e524-48a5-a079-761c6ee24020" />
      </body>
      <title>ASP.NET AJAX Extensions Internals - ScriptResourceHandler</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,7d51552e-e524-48a5-a079-761c6ee24020.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,7d51552e-e524-48a5-a079-761c6ee24020.aspx</link>
      <pubDate>Sun, 03 Jun 2007 09:48:50 GMT</pubDate>
      <description>&lt;p&gt;
&lt;strong&gt;Where were we?&lt;/strong&gt; 
&lt;/p&gt;
&lt;p&gt;
In my previous posts about MS AJAX Extensions I talked about the additions to the
web.config, Serialization, proxy generation, and ScriptHandlerFactory, that is the
factory that handles *.asmx requests and *_AppService.axd requests. To refresh memory,
what the ScriptHandlerFactory does is to check if the request has application/json
ContentType (a REST method request) or the request path ends with /js or /jsdebug
(a REST client proxy request). If it is a REST method request (&lt;u&gt;&lt;font color=#0000ff&gt;http://localhost/AJAXServerSide1/AjaxWebService.asmx/GetModifiedUser&lt;/font&gt;&lt;/u&gt;),
it gets the web service data, calls the requested method and returns the result. If
it is a REST client proxy request (&lt;font color=#0000ff&gt;&lt;u&gt;http://localhost/AJAXServerSide1/AjaxWebService.asmx/js&lt;/u&gt;&lt;/font&gt;),
it returns the generated client proxy. If it isn’t a REST method request or a REST
client proxy request, it delegates the request to the “normal” *.asmx HttpHandler.
&lt;/p&gt;
&lt;p&gt;
The&amp;nbsp; HttpHandler for *_AppService.axd exists to allow the developer to use some
application services with AJAX. The only available application services available
in v1.0 are Profile_JSON_AppService.axd and Authentication_JSON_AppService.axd. The
profile service exposes the methods: 
&lt;/p&gt;
&lt;blockquote dir=ltr style="MARGIN-RIGHT: 0px"&gt; 
&lt;p&gt;
•&amp;nbsp;GetAllPropertiesForCurrentUser&lt;br&gt;
•&amp;nbsp;GetPropertiesForCurrentUser&lt;br&gt;
•&amp;nbsp; SetPropertiesForCurrentUser. 
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
The authentication service exposes the following methods:
&lt;/p&gt;
&lt;blockquote dir=ltr style="MARGIN-RIGHT: 0px"&gt; 
&lt;p&gt;
•&amp;nbsp;Login&lt;br&gt;
•&amp;nbsp;Logout
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
To use the services, we have to enable them in the web.config. For the profile service,
we have to set the properties that can be read and write by MS AJAX. For the authentication
service we can specify if it requires SSL or not.
&lt;/p&gt;
&lt;p&gt;
There is a role service that exposes the method GetRolesForUser but it isn’t enabled
in the current version.&lt;br&gt;
The default implementation of the services can be changed, but I won’t be touching
that until we study the ScriptManager.
&lt;/p&gt;
&lt;p&gt;
The last HttpHandler that MS AJAX adds to the web.config is the ScriptResourceHandler,
for the path ScriptResource.axd. Lets study it in more detail…
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;ScriptResourceHandler in detail&lt;/strong&gt; 
&lt;/p&gt;
&lt;p&gt;
The main function performed by the ScriptResourceHandler is to load scripts from resources
stored in the assembly and adding localized resources to the scripts.
&lt;/p&gt;
&lt;p&gt;
A request to the ScriptResource.axd must be done at the root level for the application
(~/ScriptResource.axd). The request has the information needed to process it encrypted
in the query string (the encryption and decryption process is done using the EncryptString
and DecryptString methods of the System.Web.UI.Page class). The decrypted format for
the query string is:
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;“d=” + 1 character that indicates additional processing + assembly name + ‘|’
+ resource name + ‘|’ + cultureName.&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
The first character can be ‘u’, ‘U’, ‘z’ or ‘Z’. An uppercase character indicates
that the feature is enabled and the lowercase character indicates that the feature
is disabled. The ‘Z’ indicates that the resource has to be compressed (using GZip).
The ‘U’ indicates to add some code to the end of the script, to notify the MS AJAX
runtime that script has been loaded. The code that gets added to the script is:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;if&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(Sys)!==&lt;span style="COLOR: #a31515"&gt;'undefined'&lt;/span&gt;)Sys.Application.notifyScriptLoaded();
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
The assembly name and the resource name must be specified. If not, an error 404 (page
not found) will be returned. The culture name is used to set the CurrentThead.CurrentUICulture
property. If no culture is specified, the invariant culture is used.
&lt;/p&gt;
&lt;p&gt;
To expose resources stored in an assembly, the assembly level attributes ScriptResourceAttribute
and WebResourceAttribute have to be used.
&lt;/p&gt;
&lt;p&gt;
The ScriptResourceAttribute has 3 important properties: ScriptName, ScriptResourceName
and TypeName. The ScriptName property will be compared to the requested resource name.
ScriptResourceName points to a resource file that contains strings. The TypeName property
specifies a script type that will be created containing the localized strings (of
the CurrentUICulture, or the default ones if no CurrentUICulture specific resources
exist) present in the resource specified by ScriptResourceName.
&lt;/p&gt;
&lt;p&gt;
The WebResourceAttribute has 3 important properties: WebResource, ContentType and
PerformSubstitution. The WebResource property will be compared to the requested resource.
ContentType specifies the type of data stored in the resource and will be used to
write the ContentType for the response. The PerformSubstitution property is used by
the ScriptResourceHandler in order to convert expressions like:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;lt;%= WebResource(&lt;span style="COLOR: #a31515"&gt;"MyResources.JScript2.js"&lt;/span&gt;)
%&amp;gt; or &amp;lt;%= ScriptResource(&lt;span style="COLOR: #a31515"&gt;"MyResources.JScript2.js"&lt;/span&gt;)
%&amp;gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
To the URL of the resource. If WebResource is used, the generated URL will start with
“WebResource.axd?d=”. For ScriptResource, the generated URL will start with “ScriptResource.axd?d=”.
The substitution is performed using regular expressions.
&lt;/p&gt;
&lt;p&gt;
When a resource in an assembly is requested, the assembly is inspected for the assembly
level attributes ScriptResourceAttribute and WebResourceAttribute. Information about
the requested resource is stored in the class ScriptResourceInfo, that has the properties
of ScriptResourceAttribute and WebResourceAttribute combined. For the same resource
name, we can have a ScriptResourceAttribute and a WebResourceAttribute. If only ScriptResourceAttribute
is specified, the default content type is "application/x-javascript". The ScriptResourceInfo
is cached using the assembly and resource name as the cache key.
&lt;/p&gt;
&lt;p&gt;
When a resource that ends with .debug.js is requested, the release mode resource (resource
name that ends with .js) is also requested. At least one of those resources has to
exist.
&lt;/p&gt;
&lt;p&gt;
If we have set the property EnableCaching for the ScriptResourceHandler in the configuration
section, the response will be cached using the ASP.NET output cache by the server
for a year.
&lt;/p&gt;
&lt;p&gt;
The response will be generated in 3 steps:
&lt;/p&gt;
&lt;blockquote dir=ltr style="MARGIN-RIGHT: 0px"&gt; 
&lt;p&gt;
•&amp;nbsp;The requested resource will be read using the GetManifestResourceStream method
from the Assembly class.&amp;nbsp; If PerformSubstitution is enabled, the substitution
explained above is performed.&lt;br&gt;
•&amp;nbsp;If the ScriptResourceAttribute is used, a ResourceManager for the resource
file with the localized resources is obtained, and some script is added to save the
resources (see the code below)&lt;br&gt;
•&amp;nbsp;If the MS AJAX runtime has to be notified of the loading of the script, add
the script line shown above.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;strong&gt;Example&lt;/strong&gt; 
&lt;/p&gt;
&lt;p&gt;
If we have the following assembly level attributes:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
[assembly: &lt;span style="COLOR: #2b91af"&gt;ScriptResource&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"MyResources.JScript1.js"&lt;/span&gt;, &lt;span style="COLOR: #a31515"&gt;"MyResources.MyStrings"&lt;/span&gt;, &lt;span style="COLOR: #a31515"&gt;"MyResources.Res"&lt;/span&gt;)]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
[assembly: &lt;span style="COLOR: #2b91af"&gt;WebResource&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"MyResources.JScript1.js"&lt;/span&gt;, &lt;span style="COLOR: #a31515"&gt;"application/x-javascript"&lt;/span&gt;,
PerformSubstitution=&lt;span style="COLOR: blue"&gt;true&lt;/span&gt;)]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
[assembly: &lt;span style="COLOR: #2b91af"&gt;WebResource&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"MyResources.JScript2.js"&lt;/span&gt;, &lt;span style="COLOR: #a31515"&gt;"application/x-javascript"&lt;/span&gt;)]
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
The file MyResources.JScript1.js is like this:&lt;br&gt;
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;//jscript1&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;lt;%= WebResource(&lt;span style="COLOR: #a31515"&gt;"MyResources.JScript2.js"&lt;/span&gt;)
%&amp;gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The file MyStrings.resx has the string named String1 = “This is a test”, when the
resource “MyResources.JScript1.js” is requested, the response content is:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;//jscript1&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
WebResource.axd?d=aGTLuR-3gZaSvlaJzlNqJOqXDQAwO3kOV34svo62fA708VHtJJ6R4HtCd41V1jZv0&amp;amp;t=633164083963984167
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Type.registerNamespace(&lt;span style="COLOR: #a31515"&gt;'MyResources'&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
MyResources.Res={
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;"String1"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"This is
a test!"&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
};
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;if&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(Sys)!==&lt;span style="COLOR: #a31515"&gt;'undefined'&lt;/span&gt;)Sys.Application.notifyScriptLoaded();
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;If you add another resource file to localize the resources for spanish
(MyStrings.es-ES.resx) and configure the application to use the Spanish UI culture,
the response for the resource “MyResources.JScript1.js” is:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;//jscript1&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
WebResource.axd?d=aGTLuR-3gZaSvlaJzlNqJOqXDQAwO3kOV34svo62fA708VHtJJ6R4HtCd41V1jZv0&amp;amp;t=633164083963984167
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Type.registerNamespace(&lt;span style="COLOR: #a31515"&gt;'MyResources'&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
MyResources.Res={
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #a31515"&gt;"String1"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"¡Esto
es una prueba!"&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
};
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;if&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(Sys)!==&lt;span style="COLOR: #a31515"&gt;'undefined'&lt;/span&gt;)Sys.Application.notifyScriptLoaded();
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
That's all for now. In a next post I'll finally finish explaining all the elements
present in the web.config for an asp.net ajax application.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=7d51552e-e524-48a5-a079-761c6ee24020" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,7d51552e-e524-48a5-a079-761c6ee24020.aspx</comments>
      <category>Ajax;ASP.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=50bc4c5a-3e40-4f81-8137-f7843d4a486d</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,50bc4c5a-3e40-4f81-8137-f7843d4a486d.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,50bc4c5a-3e40-4f81-8137-f7843d4a486d.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=50bc4c5a-3e40-4f81-8137-f7843d4a486d</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In <a href="http://www.manuelabadia.com/blog/PermaLink,guid,22a125d3-1ed3-422b-ba2b-89ed63febce3.aspx">my
last post about MS AJAX</a> I gave a brief explanation about the web.config changes
needed and explained the serialization process. 
</p>
        <p>
Now, I'm going to explain how a client proxy is generated. As I told in the last post,
the WebServiceClientProxyGenerator.GetClientProxyScript method was were all the job
was done.
</p>
        <p>
There are a few classes involved in the client proxy generation:
</p>
        <ul>
          <li>
WebServiceTypeData, that is used to store type information about the web service to
call.</li>
          <li>
WebServiceMethodData, that is used to store information about a web service method
(parameters, return type, caching, etc), and it has the functionality to invoke the
method.</li>
          <li>
WebServiceParameterData, used to store information about a parameter of a web service
method.</li>
          <li>
WebServiceData. This class uses the previous classes and has a lot of logic. Basically
a WebServiceData instance is created for each web service to call (for each instance
there is an associated WebServiceTypeData instance). When the web service methods
are required, the EnsureMethods method uses reflection to obtain all WebMethods from
the type (and its ancestors).</li>
        </ul>
        <p>
By default, a web service can't be called from client script. To change this, the
web service needs the ScriptServiceAttribute applied to it.
</p>
        <p>
To be able to call a web method from client script, the parameters and return types
of the web method have to be available in client script, and the web service needs
to have the WebMethodAttribute (the ScriptMethodAttribute should be used only to override
the default invocation method and respone format, that is HTTP POST and JSON). If
a web service method needs a parameter of a custom type, we have to use the GenerateScriptTypeAttribute
attribute in the method or in the web service so MS AJAX will automatically generate
a client side class for that type.
</p>
        <p>
So when the methods are processed, the ClientTypes property will be filled in the
ProcessClientTypes method with a list of the types that need to be available in client
script.
</p>
        <p>
However, the automatic type generation has some limitations, as the GenerateScriptTypeAttribute
can not be applied to types implementing IEnumerable or IDictionary, interfaces, abstract
classes, types without a public parameterless constructor, and generic types with
more than one parameter.
</p>
        <p>
The WebServiceData class also inherits from the JavaScriptTypeResolver class to provide
string to type conversion (and viceversa) for the serialization/deserialization process.
You may be wondering why the SimpleTypeResolver isn't used, but as the GenerateScriptTypeAttribute
has a property called ScriptTypeId that modifies the __type field stored in the JSON,
another type resolver was needed.
</p>
        <p>
As you can see, the WebServiceData class does a lot of work, so to get WebServiceData
instances the static method GetWebServiceData is used because it caches instances
by URL.
</p>
        <p>
If you don't want to create a new class for a few methods, you can add them to your
ASPX page and call them directly. For this to work, the methods should be static and
have the WebMethodAttribute attribute applied.
</p>
        <p>
The ClientProxyGenerator class uses a WebServiceData instance and generates the client
proxy code, although the code calls to the static method GetClientProxyScript of the
WebServiceClientProxyGenerator class to get the generated client proxy code, because
it performs caching based on the web service type and the modified time of the associated
assembly. 
</p>
        <p>
For the following web service:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
[<span style="COLOR: #2b91af">WebService</span>(Namespace = <span style="COLOR: #a31515">"http://tempuri.org/"</span>)]
</p>
          <p style="MARGIN: 0px">
[<span style="COLOR: #2b91af">WebServiceBinding</span>(ConformsTo = <span style="COLOR: #2b91af">WsiProfiles</span>.BasicProfile1_1)]
</p>
          <p style="MARGIN: 0px">
[<span style="COLOR: #2b91af">ScriptService</span>]
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">class</span>
            <span style="COLOR: #2b91af">AjaxWebService</span> {
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    [<span style="COLOR: #2b91af">WebMethod</span>]
</p>
          <p style="MARGIN: 0px">
    [<span style="COLOR: #2b91af">GenerateScriptType</span>(<span style="COLOR: blue">typeof</span>(<span style="COLOR: #2b91af">User</span>))]
</p>
          <p style="MARGIN: 0px">
    [<span style="COLOR: #2b91af">GenerateScriptType</span>(<span style="COLOR: blue">typeof</span>(<span style="COLOR: #2b91af">Address</span>))]
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: #2b91af">User</span> GetModifiedUser(<span style="COLOR: #2b91af">User</span> usr)
{
</p>
          <p style="MARGIN: 0px">
        usr.ID = usr.ID * 2;
</p>
          <p style="MARGIN: 0px">
        usr.Name = <span style="COLOR: #a31515">"Manu"</span>;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">return</span> usr;
</p>
          <p style="MARGIN: 0px">
    }   
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
the User and Address classes were introduced in the previous post.<!--EndFragment--></p>
        <p>
the generated proxy is:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> AjaxWebService=<span style="COLOR: blue">function</span>()
{
</p>
          <p style="MARGIN: 0px">
    AjaxWebService.initializeBase(<span style="COLOR: blue">this</span>);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>._timeout = 0;
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>._userContext = <span style="COLOR: blue">null</span>;
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>._succeeded = <span style="COLOR: blue">null</span>;
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>._failed = <span style="COLOR: blue">null</span>;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
AjaxWebService.prototype={
</p>
          <p style="MARGIN: 0px">
    GetModifiedUser:<span style="COLOR: blue">function</span>(usr,succeededCallback,
failedCallback, userContext) {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">return</span><span style="COLOR: blue">this</span>._invoke(AjaxWebService.get_path(), <span style="COLOR: #a31515">'GetModifiedUser'</span>,<span style="COLOR: blue">false</span>,{
</p>
          <p style="MARGIN: 0px">
            usr:usr
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
        ,succeededCallback,failedCallback,userContext);
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
AjaxWebService.registerClass(<span style="COLOR: #a31515">'AjaxWebService'</span>,Sys.Net.WebServiceProxy);
</p>
          <p style="MARGIN: 0px">
AjaxWebService._staticInstance = <span style="COLOR: blue">new</span> AjaxWebService();
</p>
          <p style="MARGIN: 0px">
AjaxWebService.set_path = <span style="COLOR: blue">function</span>(value) {
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">var</span> e = Function._validateParams(arguments,
[{
</p>
          <p style="MARGIN: 0px">
        name: <span style="COLOR: #a31515">'path'</span>,
type: String
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
    ]); <span style="COLOR: blue">if</span> (e) <span style="COLOR: blue">throw</span> e;
AjaxWebService._staticInstance._path = value;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
AjaxWebService.get_path = <span style="COLOR: blue">function</span>() {
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">return</span> AjaxWebService._staticInstance._path;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
AjaxWebService.set_timeout = <span style="COLOR: blue">function</span>(value) {
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">var</span> e = Function._validateParams(arguments,
[{
</p>
          <p style="MARGIN: 0px">
        name: <span style="COLOR: #a31515">'timeout'</span>,
type: Number
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
    ]); <span style="COLOR: blue">if</span> (e) <span style="COLOR: blue">throw</span> e; <span style="COLOR: blue">if</span> (value
&amp;lt; 0) {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">throw</span> Error.argumentOutOfRange(<span style="COLOR: #a31515">'value'</span>,
value, Sys.Res.invalidTimeout);
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
    AjaxWebService._staticInstance._timeout = value;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
AjaxWebService.get_timeout = <span style="COLOR: blue">function</span>() {
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">return</span> AjaxWebService._staticInstance._timeout;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
AjaxWebService.set_defaultUserContext = <span style="COLOR: blue">function</span>(value)
{
</p>
          <p style="MARGIN: 0px">
    AjaxWebService._staticInstance._userContext = value;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
AjaxWebService.get_defaultUserContext = <span style="COLOR: blue">function</span>()
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">return</span> AjaxWebService._staticInstance._userContext;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
AjaxWebService.set_defaultSucceededCallback = <span style="COLOR: blue">function</span>(value)
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">var</span> e = Function._validateParams(arguments,
[{
</p>
          <p style="MARGIN: 0px">
        name: <span style="COLOR: #a31515">'defaultSucceededCallback'</span>,
type: Function
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
    ]); <span style="COLOR: blue">if</span> (e) <span style="COLOR: blue">throw</span> e;
AjaxWebService._staticInstance._succeeded = value;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
AjaxWebService.get_defaultSucceededCallback = <span style="COLOR: blue">function</span>()
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">return</span> AjaxWebService._staticInstance._succeeded;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
AjaxWebService.set_defaultFailedCallback = <span style="COLOR: blue">function</span>(value)
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">var</span> e = Function._validateParams(arguments,
[{
</p>
          <p style="MARGIN: 0px">
        name: <span style="COLOR: #a31515">'defaultFailedCallback'</span>,
type: Function
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
    ]); <span style="COLOR: blue">if</span> (e) <span style="COLOR: blue">throw</span> e;
AjaxWebService._staticInstance._failed = value;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
AjaxWebService.get_defaultFailedCallback = <span style="COLOR: blue">function</span>()
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">return</span> AjaxWebService._staticInstance._failed;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
AjaxWebService.set_path(<span style="COLOR: #a31515">"/AJAXServerSide1/AjaxWebService.asmx"</span>);
</p>
          <p style="MARGIN: 0px">
AjaxWebService.GetModifiedUser= <span style="COLOR: blue">function</span>(usr,onSuccess,onFailed,userContext)
{
</p>
          <p style="MARGIN: 0px">
    AjaxWebService._staticInstance.GetModifiedUser(usr,onSuccess,onFailed,userContext);
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> gtc = Sys.Net.WebServiceProxy._generateTypedConstructor;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span> (<span style="COLOR: blue">typeof</span>(Address)
=== <span style="COLOR: #a31515">'undefined'</span>) {
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">var</span> Address=gtc(<span style="COLOR: #a31515">"Address"</span>);
</p>
          <p style="MARGIN: 0px">
    Address.registerClass(<span style="COLOR: #a31515">'Address'</span>);
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span> (<span style="COLOR: blue">typeof</span>(User)
=== <span style="COLOR: #a31515">'undefined'</span>) {
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">var</span> User=gtc(<span style="COLOR: #a31515">"User"</span>);
</p>
          <p style="MARGIN: 0px">
    User.registerClass(<span style="COLOR: #a31515">'User'</span>);
</p>
          <p style="MARGIN: 0px">
} 
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
The generated proxy class is called like the web service, and inherits from the Sys.Net.WebServiceProxy
class, which has the functionality to invoke a web service. The class have some properties
set in order call the specific web service that it is proxying, and the web methods
exposed (GetModifiedUser in our case).
</p>
        <p>
After the class to call the web service, the User and Address classes are created
and registered to be used by client code (thanks to the GenerateScriptTypeAttribute).
However, no property of the original classes is generated in client script. The core
of this client classes is the call to the Sys.Net.WebServiceProxy._generateTypedConstructor
method. This method creates a new class that accepts an object as a parameter for
the constructor. The constructor of the class will iterate through the members of
the object passed as the parameter and copy them to the current instance.
</p>
        <p>
So you can create an instance of the Address class that has 2 fields (propertyOne
and propertyTwo) like this:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">new</span> Address({<span style="COLOR: #a31515">"firstField"</span>:<span style="COLOR: #a31515">"firstValue"</span>,<span style="COLOR: #a31515">"secondField"</span>:<span style="COLOR: #a31515">"secondValue"</span>}).
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
and accessing to Address.firstField will return "firstValue".
</p>
        <p>
So if you want to call the previous web service from client script you can do something
like this:
</p>
        <p>
        
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">function</span> callWebService()
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> user
= <span style="COLOR: blue">new</span> User();
</p>
          <p style="MARGIN: 0px">
            user.ID = 1;
</p>
          <p style="MARGIN: 0px">
            user.Name = <span style="COLOR: #a31515">"Manuel"</span>;
</p>
          <p style="MARGIN: 0px">
            user.SurName = <span style="COLOR: #a31515">"Abadia"</span>;
</p>
          <p style="MARGIN: 0px">
            user.CreationDate = <span style="COLOR: blue">new</span> Date();
</p>
          <p style="MARGIN: 0px">
            user.Address = <span style="COLOR: blue">new</span> Address();
</p>
          <p style="MARGIN: 0px">
            user.Address.FirstLine = <span style="COLOR: #a31515">"C/
Torre Alvarez"</span>;
</p>
          <p style="MARGIN: 0px">
            user.Address.SecondLine = <span style="COLOR: #a31515">"Murcia,
2007"</span>;
</p>
          <p style="MARGIN: 0px">
            user.Address.Country = <span style="COLOR: #a31515">"Spain"</span>;
</p>
          <p style="MARGIN: 0px">
            AjaxWebService.GetModifiedUser(user,
OnSucceeded, OnError);
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">function</span> OnSucceeded(result)
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> RsltElem
= document.getElementById(<span style="COLOR: #a31515">"Results"</span>);
</p>
          <p style="MARGIN: 0px">
            RsltElem.innerHTML = result.Name
+ <span style="COLOR: #a31515">"["</span> + result.ID + <span style="COLOR: #a31515">"]"</span>;
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">function</span> OnError(message)
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
           alert(message.get_message() + <span style="COLOR: #a31515">"
"</span> + message.get_stackTrace());
</p>
          <p style="MARGIN: 0px">
        }
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
when the User instance is created it contains no members, but you keep adding them
in each assignment (this is how JavaScript works). You can even add nonexisting members
like user.Foo = "This property doesn't exists in server code" and they will be ignored
on the server side in the deserialization process.
</p>
        <p>
When the GetModifiedUser method is called from client script, it generates an asynchronous
HTTP request to the web service (<a href="http://localhost/AJAXServerSide1/AjaxWebService.asmx/GetModifiedUser">http://localhost/AJAXServerSide1/AjaxWebService.asmx/GetModifiedUser</a> in
my case) with the following posted data:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
{<span style="COLOR: #a31515">"usr"</span>:{<span style="COLOR: #a31515">"__type"</span>:<span style="COLOR: #a31515">"User"</span>,<span style="COLOR: #a31515">"ID"</span>:1,<span style="COLOR: #a31515">"Name"</span>:<span style="COLOR: #a31515">"Manuel"</span>,<span style="COLOR: #a31515">"SurName"</span>:<span style="COLOR: #a31515">"Abadia"</span>,<span style="COLOR: #a31515">"CreationDate"</span>:<span style="COLOR: #a31515">"\/Date(1174133124369)\/"</span>,<span style="COLOR: #a31515">"Address"</span>:{<span style="COLOR: #a31515">"__type"</span>:<span style="COLOR: #a31515">"Address"</span>,<span style="COLOR: #a31515">"FirstLine"</span>:<span style="COLOR: #a31515">"C/
Torre Alvarez"</span>,<span style="COLOR: #a31515">"SecondLine"</span>:<span style="COLOR: #a31515">"Murcia,
2007"</span>,<span style="COLOR: #a31515">"Country"</span>:<span style="COLOR: #a31515">"Spain"</span>}}}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
and the server generates a response with the following data:
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
{<span style="COLOR: #a31515">"__type"</span>:<span style="COLOR: #a31515">"User"</span>,<span style="COLOR: #a31515">"ID"</span>:2,<span style="COLOR: #a31515">"Name"</span>:<span style="COLOR: #a31515">"Manu"</span>,<span style="COLOR: #a31515">"SurName"</span>:<span style="COLOR: #a31515">"Abadia"</span>,<span style="COLOR: #a31515">"Address"</span>:{<span style="COLOR: #a31515">"__type"</span>:<span style="COLOR: #a31515">"Address"</span>,<span style="COLOR: #a31515">"FirstLine"</span>:<span style="COLOR: #a31515">"C/
Torre Alvarez"</span>,<span style="COLOR: #a31515">"SecondLine"</span>:<span style="COLOR: #a31515">"Murcia,
2007"</span>,<span style="COLOR: #a31515">"Country"</span>:<span style="COLOR: #a31515">"Spain"</span>},<span style="COLOR: #a31515">"CreationDate"</span>:<span style="COLOR: #a31515">"\/Date(1174133124369)\/"</span>}
</p>
        </div>
        <p>
that is passed to directly the User constructor in order to generate the returned
value from the web service.
</p>
        <p>
In my next post about MS AJAX I'll sumarize what we have learned and how it applies
to the ScriptHandlerFactory, the application web services, and then continue
with the next HttpHandler, the ScriptResourceHandler.
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=50bc4c5a-3e40-4f81-8137-f7843d4a486d" />
      </body>
      <title>ASP.NET AJAX Extensions Internals - Web Service Proxy Generation</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,50bc4c5a-3e40-4f81-8137-f7843d4a486d.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,50bc4c5a-3e40-4f81-8137-f7843d4a486d.aspx</link>
      <pubDate>Sat, 17 Mar 2007 13:09:19 GMT</pubDate>
      <description>&lt;p&gt;
In &lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,22a125d3-1ed3-422b-ba2b-89ed63febce3.aspx"&gt;my
last post about MS AJAX&lt;/a&gt; I gave a brief explanation about the web.config changes
needed and explained the serialization process. 
&lt;/p&gt;
&lt;p&gt;
Now, I'm going to explain how a client proxy is generated. As I told in the last post,
the WebServiceClientProxyGenerator.GetClientProxyScript method was were all the job
was done.
&lt;/p&gt;
&lt;p&gt;
There are a few classes involved in the client proxy generation:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
WebServiceTypeData, that is used to store type information about the web service to
call.&lt;/li&gt;
&lt;li&gt;
WebServiceMethodData, that is used to store information about a web service method
(parameters, return type, caching, etc), and it has the functionality to invoke the
method.&lt;/li&gt;
&lt;li&gt;
WebServiceParameterData, used to store information about a parameter of a web service
method.&lt;/li&gt;
&lt;li&gt;
WebServiceData. This class uses the previous classes and has a lot of logic. Basically
a WebServiceData instance is created for each web service to call (for each instance
there is an associated WebServiceTypeData instance). When the web service methods
are required, the EnsureMethods method uses reflection to obtain all WebMethods from
the type (and its ancestors).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
By default, a web service can't be called from client script. To change this, the
web service needs the ScriptServiceAttribute applied to it.
&lt;/p&gt;
&lt;p&gt;
To be able to call a web method from client script, the parameters and return types
of the web method have to be available in client script, and the web service needs
to have the WebMethodAttribute (the ScriptMethodAttribute should be used only to override
the default invocation method and respone format, that is HTTP POST and JSON). If
a web service method needs a parameter of a custom type, we have to use the GenerateScriptTypeAttribute
attribute in the method or in the web service so MS AJAX will automatically generate
a client side class for that type.
&lt;/p&gt;
&lt;p&gt;
So when the methods are processed, the ClientTypes property will be filled in the
ProcessClientTypes method with a list of the types that need to be available in client
script.
&lt;/p&gt;
&lt;p&gt;
However, the automatic type generation has some limitations, as the GenerateScriptTypeAttribute
can not be applied to types implementing IEnumerable or IDictionary, interfaces, abstract
classes, types without a public parameterless constructor, and generic types with
more than one parameter.
&lt;/p&gt;
&lt;p&gt;
The WebServiceData class also inherits from the JavaScriptTypeResolver class to provide
string to type conversion (and viceversa) for the serialization/deserialization process.
You may be wondering why the SimpleTypeResolver isn't used, but as the GenerateScriptTypeAttribute
has a property called ScriptTypeId that modifies the __type field stored in the JSON,
another type resolver was needed.
&lt;/p&gt;
&lt;p&gt;
As you can see, the WebServiceData class does a lot of work, so to get WebServiceData
instances the static method GetWebServiceData is used because it caches instances
by URL.
&lt;/p&gt;
&lt;p&gt;
If you don't want to create a new class for a few methods, you can add them to your
ASPX page and call them directly. For this to work, the methods should be static and
have the WebMethodAttribute attribute applied.
&lt;/p&gt;
&lt;p&gt;
The ClientProxyGenerator class uses a WebServiceData instance and generates the client
proxy code, although the code calls to the static method GetClientProxyScript of the
WebServiceClientProxyGenerator class to get the generated client proxy code, because
it performs caching based on the web service type and the modified time of the associated
assembly. 
&lt;/p&gt;
&lt;p&gt;
For the following web service:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
[&lt;span style="COLOR: #2b91af"&gt;WebService&lt;/span&gt;(Namespace = &lt;span style="COLOR: #a31515"&gt;"http://tempuri.org/"&lt;/span&gt;)]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
[&lt;span style="COLOR: #2b91af"&gt;WebServiceBinding&lt;/span&gt;(ConformsTo = &lt;span style="COLOR: #2b91af"&gt;WsiProfiles&lt;/span&gt;.BasicProfile1_1)]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
[&lt;span style="COLOR: #2b91af"&gt;ScriptService&lt;/span&gt;]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;AjaxWebService&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="COLOR: #2b91af"&gt;WebMethod&lt;/span&gt;]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="COLOR: #2b91af"&gt;GenerateScriptType&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;User&lt;/span&gt;))]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="COLOR: #2b91af"&gt;GenerateScriptType&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;Address&lt;/span&gt;))]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;User&lt;/span&gt; GetModifiedUser(&lt;span style="COLOR: #2b91af"&gt;User&lt;/span&gt; usr)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; usr.ID = usr.ID * 2;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; usr.Name = &lt;span style="COLOR: #a31515"&gt;"Manu"&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; usr;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
the User and Address classes were introduced in the previous post.&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
the generated proxy is:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; AjaxWebService=&lt;span style="COLOR: blue"&gt;function&lt;/span&gt;()
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; AjaxWebService.initializeBase(&lt;span style="COLOR: blue"&gt;this&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._timeout = 0;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._userContext = &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._succeeded = &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._failed = &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AjaxWebService.prototype={
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; GetModifiedUser:&lt;span style="COLOR: blue"&gt;function&lt;/span&gt;(usr,succeededCallback,
failedCallback, userContext) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._invoke(AjaxWebService.get_path(), &lt;span style="COLOR: #a31515"&gt;'GetModifiedUser'&lt;/span&gt;,&lt;span style="COLOR: blue"&gt;false&lt;/span&gt;,{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; usr:usr
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; ,succeededCallback,failedCallback,userContext);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AjaxWebService.registerClass(&lt;span style="COLOR: #a31515"&gt;'AjaxWebService'&lt;/span&gt;,Sys.Net.WebServiceProxy);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AjaxWebService._staticInstance = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; AjaxWebService();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AjaxWebService.set_path = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;(value) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; e = Function._validateParams(arguments,
[{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; name: &lt;span style="COLOR: #a31515"&gt;'path'&lt;/span&gt;,
type: String
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ]); &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (e) &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; e;
AjaxWebService._staticInstance._path = value;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AjaxWebService.get_path = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; AjaxWebService._staticInstance._path;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AjaxWebService.set_timeout = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;(value) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; e = Function._validateParams(arguments,
[{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; name: &lt;span style="COLOR: #a31515"&gt;'timeout'&lt;/span&gt;,
type: Number
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ]); &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (e) &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; e; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (value
&amp;amp;lt; 0) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; Error.argumentOutOfRange(&lt;span style="COLOR: #a31515"&gt;'value'&lt;/span&gt;,
value, Sys.Res.invalidTimeout);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; AjaxWebService._staticInstance._timeout = value;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AjaxWebService.get_timeout = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; AjaxWebService._staticInstance._timeout;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AjaxWebService.set_defaultUserContext = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;(value)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; AjaxWebService._staticInstance._userContext = value;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AjaxWebService.get_defaultUserContext = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;()
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; AjaxWebService._staticInstance._userContext;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AjaxWebService.set_defaultSucceededCallback = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;(value)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; e = Function._validateParams(arguments,
[{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; name: &lt;span style="COLOR: #a31515"&gt;'defaultSucceededCallback'&lt;/span&gt;,
type: Function
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ]); &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (e) &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; e;
AjaxWebService._staticInstance._succeeded = value;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AjaxWebService.get_defaultSucceededCallback = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;()
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; AjaxWebService._staticInstance._succeeded;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AjaxWebService.set_defaultFailedCallback = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;(value)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; e = Function._validateParams(arguments,
[{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; name: &lt;span style="COLOR: #a31515"&gt;'defaultFailedCallback'&lt;/span&gt;,
type: Function
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ]); &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (e) &lt;span style="COLOR: blue"&gt;throw&lt;/span&gt; e;
AjaxWebService._staticInstance._failed = value;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AjaxWebService.get_defaultFailedCallback = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;()
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; AjaxWebService._staticInstance._failed;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AjaxWebService.set_path(&lt;span style="COLOR: #a31515"&gt;"/AJAXServerSide1/AjaxWebService.asmx"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
AjaxWebService.GetModifiedUser= &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;(usr,onSuccess,onFailed,userContext)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; AjaxWebService._staticInstance.GetModifiedUser(usr,onSuccess,onFailed,userContext);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; gtc = Sys.Net.WebServiceProxy._generateTypedConstructor;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(Address)
=== &lt;span style="COLOR: #a31515"&gt;'undefined'&lt;/span&gt;) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; Address=gtc(&lt;span style="COLOR: #a31515"&gt;"Address"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Address.registerClass(&lt;span style="COLOR: #a31515"&gt;'Address'&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(User)
=== &lt;span style="COLOR: #a31515"&gt;'undefined'&lt;/span&gt;) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; User=gtc(&lt;span style="COLOR: #a31515"&gt;"User"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; User.registerClass(&lt;span style="COLOR: #a31515"&gt;'User'&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
} 
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The generated proxy class is called like the web service, and inherits from the Sys.Net.WebServiceProxy
class, which has the functionality to invoke a web service. The class have some properties
set in order call the specific web service that it is proxying, and the web methods
exposed (GetModifiedUser in our case).
&lt;/p&gt;
&lt;p&gt;
After the class to call the web service, the User and Address classes are created
and registered to be used by client code (thanks to the GenerateScriptTypeAttribute).
However, no property of the original classes is generated in client script. The core
of this client classes is the call to the Sys.Net.WebServiceProxy._generateTypedConstructor
method. This method creates a new class that accepts an object as a parameter for
the constructor. The constructor of the class will iterate through the members of
the object passed as the parameter and copy them to the current instance.
&lt;/p&gt;
&lt;p&gt;
So you can create an instance of the Address class that has 2 fields (propertyOne
and propertyTwo) like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;new&lt;/span&gt; Address({&lt;span style="COLOR: #a31515"&gt;"firstField"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"firstValue"&lt;/span&gt;,&lt;span style="COLOR: #a31515"&gt;"secondField"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"secondValue"&lt;/span&gt;}).
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
and accessing to Address.firstField will return "firstValue".
&lt;/p&gt;
&lt;p&gt;
So if you want to call the previous web service from client script you can do something
like this:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;function&lt;/span&gt; callWebService()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; user
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; User();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; user.ID = 1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; user.Name = &lt;span style="COLOR: #a31515"&gt;"Manuel"&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; user.SurName = &lt;span style="COLOR: #a31515"&gt;"Abadia"&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; user.CreationDate = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; Date();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; user.Address = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; Address();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; user.Address.FirstLine = &lt;span style="COLOR: #a31515"&gt;"C/
Torre Alvarez"&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; user.Address.SecondLine = &lt;span style="COLOR: #a31515"&gt;"Murcia,
2007"&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; user.Address.Country = &lt;span style="COLOR: #a31515"&gt;"Spain"&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; AjaxWebService.GetModifiedUser(user,
OnSucceeded, OnError);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;function&lt;/span&gt; OnSucceeded(result)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; RsltElem
= document.getElementById(&lt;span style="COLOR: #a31515"&gt;"Results"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; RsltElem.innerHTML = result.Name
+ &lt;span style="COLOR: #a31515"&gt;"["&lt;/span&gt; + result.ID + &lt;span style="COLOR: #a31515"&gt;"]"&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;function&lt;/span&gt; OnError(message)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; alert(message.get_message() + &lt;span style="COLOR: #a31515"&gt;"
"&lt;/span&gt; + message.get_stackTrace());
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
when the User instance is created it contains no members, but you keep adding them
in each assignment (this is how JavaScript works). You can even add nonexisting members
like user.Foo = "This property doesn't exists in server code" and they will be ignored
on the server side in the deserialization process.
&lt;/p&gt;
&lt;p&gt;
When the GetModifiedUser method is called from client script, it generates an asynchronous
HTTP request to the web service (&lt;a href="http://localhost/AJAXServerSide1/AjaxWebService.asmx/GetModifiedUser"&gt;http://localhost/AJAXServerSide1/AjaxWebService.asmx/GetModifiedUser&lt;/a&gt; in
my case) with the following posted data:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
{&lt;span style="COLOR: #a31515"&gt;"usr"&lt;/span&gt;:{&lt;span style="COLOR: #a31515"&gt;"__type"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"User"&lt;/span&gt;,&lt;span style="COLOR: #a31515"&gt;"ID"&lt;/span&gt;:1,&lt;span style="COLOR: #a31515"&gt;"Name"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"Manuel"&lt;/span&gt;,&lt;span style="COLOR: #a31515"&gt;"SurName"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"Abadia"&lt;/span&gt;,&lt;span style="COLOR: #a31515"&gt;"CreationDate"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"\/Date(1174133124369)\/"&lt;/span&gt;,&lt;span style="COLOR: #a31515"&gt;"Address"&lt;/span&gt;:{&lt;span style="COLOR: #a31515"&gt;"__type"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"Address"&lt;/span&gt;,&lt;span style="COLOR: #a31515"&gt;"FirstLine"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"C/
Torre Alvarez"&lt;/span&gt;,&lt;span style="COLOR: #a31515"&gt;"SecondLine"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"Murcia,
2007"&lt;/span&gt;,&lt;span style="COLOR: #a31515"&gt;"Country"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"Spain"&lt;/span&gt;}}}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
and the server generates a response with the following data:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{&lt;span style="COLOR: #a31515"&gt;"__type"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"User"&lt;/span&gt;,&lt;span style="COLOR: #a31515"&gt;"ID"&lt;/span&gt;:2,&lt;span style="COLOR: #a31515"&gt;"Name"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"Manu"&lt;/span&gt;,&lt;span style="COLOR: #a31515"&gt;"SurName"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"Abadia"&lt;/span&gt;,&lt;span style="COLOR: #a31515"&gt;"Address"&lt;/span&gt;:{&lt;span style="COLOR: #a31515"&gt;"__type"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"Address"&lt;/span&gt;,&lt;span style="COLOR: #a31515"&gt;"FirstLine"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"C/
Torre Alvarez"&lt;/span&gt;,&lt;span style="COLOR: #a31515"&gt;"SecondLine"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"Murcia,
2007"&lt;/span&gt;,&lt;span style="COLOR: #a31515"&gt;"Country"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"Spain"&lt;/span&gt;},&lt;span style="COLOR: #a31515"&gt;"CreationDate"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"\/Date(1174133124369)\/"&lt;/span&gt;}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
that is passed to directly the User constructor in order to generate the returned
value from the web service.
&lt;/p&gt;
&lt;p&gt;
In my next post about MS AJAX I'll sumarize what we have learned and how it applies
to the ScriptHandlerFactory, the application web services,&amp;nbsp;and then continue
with the next HttpHandler, the ScriptResourceHandler.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=50bc4c5a-3e40-4f81-8137-f7843d4a486d" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,50bc4c5a-3e40-4f81-8137-f7843d4a486d.aspx</comments>
      <category>Ajax;ASP.NET;JavaScript</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=22a125d3-1ed3-422b-ba2b-89ed63febce3</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,22a125d3-1ed3-422b-ba2b-89ed63febce3.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,22a125d3-1ed3-422b-ba2b-89ed63febce3.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=22a125d3-1ed3-422b-ba2b-89ed63febce3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Some time ago I started bloging about the Client Side OOP Features of Atlas (now the
Microsoft AJAX Library. The posts are <a href="http://www.manuelabadia.com/blog/PermaLink,guid,c59facc0-301e-4e30-898d-428038828dcd.aspx">here</a> and <a href="http://www.manuelabadia.com/blog/PermaLink,guid,e440e756-b3fa-4ec2-aea7-f2f28dee1a38.aspx">here</a>). 
</p>
        <p>
As I think that most ASP.NET developers will use mainly the server side AJAX extensions
I'll start covering the internals of the server side additions to ASP.NET to support
AJAX.
</p>
        <p>
If you create a new Web Site in VS2005 using the "ASP.NET AJAX Enabled Web-Site" you'll
see that the web.config file for this web has quite a few additions to the default
one related to AJAX. The additions to the web.config are:
</p>
        <p>
1) Added some custom sections handlers to configure the new AJAX features 
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;</span>
            <span style="COLOR: #a31515">sectionGroup</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">name</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">system.web.extensions</span>"<span style="COLOR: blue"></span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">System.Web.Configuration.SystemWebExtensionsSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>"<span style="COLOR: blue">&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">      &lt;</span>
            <span style="COLOR: #a31515">sectionGroup</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">name</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">scripting</span>"<span style="COLOR: blue"></span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">System.Web.Configuration.ScriptingSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>"<span style="COLOR: blue">&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        &lt;</span>
            <span style="COLOR: #a31515">section</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">name</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">scriptResourceHandler</span>"<span style="COLOR: blue"></span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">System.Web.Configuration.ScriptingScriptResourceHandlerSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>"<span style="COLOR: blue"></span><span style="COLOR: red">requirePermission</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">false</span>"<span style="COLOR: blue"></span><span style="COLOR: red">allowDefinition</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">MachineToApplication</span>"<span style="COLOR: blue">/&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        &lt;</span>
            <span style="COLOR: #a31515">sectionGroup</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">name</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">webServices</span>"<span style="COLOR: blue"></span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">System.Web.Configuration.ScriptingWebServicesSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>"<span style="COLOR: blue">&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">          &lt;</span>
            <span style="COLOR: #a31515">section</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">name</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">jsonSerialization</span>"<span style="COLOR: blue"></span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">System.Web.Configuration.ScriptingJsonSerializationSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>"<span style="COLOR: blue"></span><span style="COLOR: red">requirePermission</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">false</span>"<span style="COLOR: blue"></span><span style="COLOR: red">allowDefinition</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">Everywhere</span>"<span style="COLOR: blue">/&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">          &lt;</span>
            <span style="COLOR: #a31515">section</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">name</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">profileService</span>"<span style="COLOR: blue"></span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">System.Web.Configuration.ScriptingProfileServiceSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>"<span style="COLOR: blue"></span><span style="COLOR: red">requirePermission</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">false</span>"<span style="COLOR: blue"></span><span style="COLOR: red">allowDefinition</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">MachineToApplication</span>"<span style="COLOR: blue">/&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">          &lt;</span>
            <span style="COLOR: #a31515">section</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">name</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">authenticationService</span>"<span style="COLOR: blue"></span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">System.Web.Configuration.ScriptingAuthenticationServiceSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>"<span style="COLOR: blue"></span><span style="COLOR: red">requirePermission</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">false</span>"<span style="COLOR: blue"></span><span style="COLOR: red">allowDefinition</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">MachineToApplication</span>"<span style="COLOR: blue">/&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        &lt;/</span>
            <span style="COLOR: #a31515">sectionGroup</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">      &lt;/</span>
            <span style="COLOR: #a31515">sectionGroup</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;/</span>
            <span style="COLOR: #a31515">sectionGroup</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
        </div>
        <p>
          <!--EndFragment-->    
<br /></p>
        <p>
2) Configured the "asp" tag prefix for controls in the AJAX implementation assembly:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;</span>
            <span style="COLOR: #a31515">pages</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">      &lt;</span>
            <span style="COLOR: #a31515">controls</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        &lt;</span>
            <span style="COLOR: #a31515">add</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">tagPrefix</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">asp</span>"<span style="COLOR: blue"></span><span style="COLOR: red">namespace</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">System.Web.UI</span>"<span style="COLOR: blue"></span><span style="COLOR: red">assembly</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>"<span style="COLOR: blue">/&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">      &lt;/</span>
            <span style="COLOR: #a31515">controls</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;/</span>
            <span style="COLOR: #a31515">pages</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
        </div>
        <p>
          <!--EndFragment-->    
<br /></p>
        <p>
3) Added the AJAX assembly reference to the compilation process:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;</span>
            <span style="COLOR: #a31515">compilation</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">debug</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">false</span>"<span style="COLOR: blue">&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">      &lt;</span>
            <span style="COLOR: #a31515">assemblies</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        &lt;</span>
            <span style="COLOR: #a31515">add</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">assembly</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>"<span style="COLOR: blue">/&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">      &lt;/</span>
            <span style="COLOR: #a31515">assemblies</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;/</span>
            <span style="COLOR: #a31515">compilation</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
        </div>
        <p>
          <!--EndFragment-->    
<br /></p>
        <p>
4) Modified the HTTP Handlers:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;</span>
            <span style="COLOR: #a31515">httpHandlers</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">      &lt;</span>
            <span style="COLOR: #a31515">remove</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">verb</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">*</span>"<span style="COLOR: blue"></span><span style="COLOR: red">path</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">*.asmx</span>"<span style="COLOR: blue">/&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">      &lt;</span>
            <span style="COLOR: #a31515">add</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">verb</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">*</span>"<span style="COLOR: blue"></span><span style="COLOR: red">path</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">*.asmx</span>"<span style="COLOR: blue"></span><span style="COLOR: red">validate</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">false</span>"<span style="COLOR: blue"></span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>"<span style="COLOR: blue">/&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">      &lt;</span>
            <span style="COLOR: #a31515">add</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">verb</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">*</span>"<span style="COLOR: blue"></span><span style="COLOR: red">path</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">*_AppService.axd</span>"<span style="COLOR: blue"></span><span style="COLOR: red">validate</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">false</span>"<span style="COLOR: blue"></span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>"<span style="COLOR: blue">/&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">      &lt;</span>
            <span style="COLOR: #a31515">add</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">verb</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">GET,HEAD</span>"<span style="COLOR: blue"></span><span style="COLOR: red">path</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">ScriptResource.axd</span>"<span style="COLOR: blue"></span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">System.Web.Handlers.ScriptResourceHandler,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>"<span style="COLOR: blue"></span><span style="COLOR: red">validate</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">false</span>"<span style="COLOR: blue">/&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;/</span>
            <span style="COLOR: #a31515">httpHandlers</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
        </div>
        <p>
          <!--EndFragment-->    
<br /></p>
        <p>
5) Added an HTTP Module:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;</span>
            <span style="COLOR: #a31515">httpModules</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">      &lt;</span>
            <span style="COLOR: #a31515">add</span>
            <span style="COLOR: blue">
            </span>
            <span style="COLOR: red">name</span>
            <span style="COLOR: blue">=</span>"<span style="COLOR: blue">ScriptModule</span>"<span style="COLOR: blue"></span><span style="COLOR: red">type</span><span style="COLOR: blue">=</span>"<span style="COLOR: blue">System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35</span>"<span style="COLOR: blue">/&gt;</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;/</span>
            <span style="COLOR: #a31515">httpModules</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
        </div>
        <p>
          <!--EndFragment-->    
<br /></p>
        <p>
6) Added the configuration sections to configure ASP.NET AJAX (the section handlers
were registered previously as explained in point 1).
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">&lt;</span>
            <span style="COLOR: #a31515">system.web.extensions</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;</span>
            <span style="COLOR: #a31515">scripting</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">      &lt;</span>
            <span style="COLOR: #a31515">webServices</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        &lt;!--</span>
            <span style="COLOR: green"> Uncomment
this line to customize maxJsonLength and add a custom converter </span>
            <span style="COLOR: blue">--&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        &lt;!--</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">      &lt;jsonSerialization maxJsonLength="500"&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">        &lt;converters&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">          &lt;add name="ConvertMe"
type="Acme.SubAcme.ConvertMeTypeConverter"/&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">        &lt;/converters&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">      &lt;/jsonSerialization&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">      </span>
            <span style="COLOR: blue">--&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        &lt;!--</span>
            <span style="COLOR: green"> Uncomment
this line to enable the authentication service. Include requireSSL="true" if appropriate. </span>
            <span style="COLOR: blue">--&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        &lt;!--</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">        &lt;authenticationService enabled="true"
requireSSL = "true|false"/&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">      </span>
            <span style="COLOR: blue">--&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        &lt;!--</span>
            <span style="COLOR: green"> Uncomment
these lines to enable the profile service. To allow profile properties to be retrieved</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">          and modified in ASP.NET
AJAX applications, you need to add each property name to the readAccessProperties
and</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">          writeAccessProperties
attributes. </span>
            <span style="COLOR: blue">--&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">        &lt;!--</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">      &lt;profileService enabled="true"</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">               
      readAccessProperties="propertyname1,propertyname2"</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">               
      writeAccessProperties="propertyname1,propertyname2" /&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">      </span>
            <span style="COLOR: blue">--&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">      &lt;/</span>
            <span style="COLOR: #a31515">webServices</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">      &lt;!--</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">      &lt;scriptResourceHandler enableCompression="true"
enableCaching="true" /&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: green">      </span>
            <span style="COLOR: blue">--&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">    &lt;/</span>
            <span style="COLOR: #a31515">scripting</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">  &lt;/</span>
            <span style="COLOR: #a31515">system.web.extensions</span>
            <span style="COLOR: blue">&gt;</span>
          </p>
        </div>
        <!--EndFragment-->
        <p>
          <br />
  
<br /></p>
        <p>
The most important additions to the web.config to support the Microsoft ASP.NET AJAX
Extensions (MS AJAX from now on) are point 4 and 5. As the ASP.NET HTTP pipeline is
very configurable, those additions can have severe implications on how request are
handled, so I'll start with them.
</p>
        <p>
In the HTTP handlers section, the first line removes the default handling for the
asmx extension, and the second one registers a new handler for the asmx extension.
This simple changes makes that any call to a web service doesn't work as we are used
to. The asmx requests now will go through the ScriptHandlerFactory.
</p>
        <p>
Usually in the HTTP handlers session we register a class that implements the IHttpHanlder
interface. The ProcessRequest method will be called to do all processing. 
</p>
        <p>
However, we can also register a class that implements an IHttpHandlerFactory. In this
case, the method GetHandler will be called in the factory, returning an IHttpHandler
that will handle the request. This is used when you want to return different IHttpHandler
instances depending on some conditions of the request.
</p>
        <p>
When a request that is handled by the ScriptHandlerFactory arrives, it checks if the
request is a REST request (REST is a way to transmit data over HTTP without using
any additional messaging layer. Consult <a href="http://en.wikipedia.org/wiki/REST">wikipedia</a> for
more information about it). If it is a REST request, the RestHandlerFactory (a MS
AJAX class) will take care of the request. If it isn't, the WebServiceHandlerFactory
will take care of it. Probably the class WebServiceHandlerFactory won't say much to
you, but this is the class that handles ASMX request in the ASP.NET 2.0, so when an
ASMX request isn't a REST request, it is handled in the same way as we're used to.  
</p>
        <p>
What is a REST request for MS AJAX? A REST request is an HTTP request that has the
ContentType property set to "application/json" (this is called a REST method request)
or an HTTP request whose path ends with "/js" or "/jsdebug" (this is called a REST
client proxy request).
</p>
        <p>
The RestHandlerFactory checks if the request is for a client proxy or for a REST method.
If the request is for a client proxy, a RestClientProxyHandler is created and servers
the request. The RestClientProxyHandler figures which client proxy has been requested,
gets the client proxy and sends it. All the hard work is done by the WebServiceClientProxyGenerator.GetClientProxyScript
method. Before entering in detail how the client script proxy is generated, lets see
how MS AJAX handles serialization.
</p>
        <p>
Data types are exchanged between client side and server side using JSON (JavaScript
Object Notation). To send data to the client side from the server, the data is serialized,
and to receive it from the client, the data is deserialized in the server.
</p>
        <p>
The main class responsible for this serialization/deserialization process is JavaScriptSerializer.
The public member for the class are:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">class</span>
            <span style="COLOR: #2b91af">JavaScriptSerializer</span>
          </p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> JavaScriptSerializer();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> JavaScriptSerializer(<span style="COLOR: #2b91af">JavaScriptTypeResolver</span> resolver);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">int</span> MaxJsonLength
{ <span style="COLOR: blue">get</span>; <span style="COLOR: blue">set</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">int</span> RecursionLimit
{ <span style="COLOR: blue">get</span>; <span style="COLOR: blue">set</span>; }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">string</span> Serialize(<span style="COLOR: blue">object</span> obj);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> Serialize(<span style="COLOR: blue">object</span> obj, <span style="COLOR: #2b91af">StringBuilder</span> output);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> T Deserialize&lt;T&gt;(<span style="COLOR: blue">string</span> input);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">object</span> DeserializeObject(<span style="COLOR: blue">string</span> input);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> T ConvertToType&lt;T&gt;(<span style="COLOR: blue">object</span> obj);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> RegisterConverters(IEnumerable&lt;<span style="COLOR: #2b91af">JavaScriptConverter</span>&gt;
converters);
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
          <br />
 <br /></p>
        <p>
The serialization fails if there are more nested objects than RecursionLimit or if
the length of the serialized object is MaxJsonLength.
</p>
        <p>
A serialized object can optionally include type information. The type information
is provided by a class that inherits from JavaScriptTypeResolver, that has the following
methods to get a type from a string and viceversa: 
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">abstract</span>
            <span style="COLOR: blue">class</span>
            <span style="COLOR: #2b91af">JavaScriptTypeResolver</span>
          </p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">abstract</span><span style="COLOR: #2b91af">Type</span> ResolveType(<span style="COLOR: blue">string</span> id);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">abstract</span><span style="COLOR: blue">string</span> ResolveTypeId(<span style="COLOR: #2b91af">Type</span> type);
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
 
</p>
        <p>
The serializer will add the type information in a field called __type if it has an
associated JavaScriptTypeResolver.
</p>
        <p>
As the JavaScriptSerializer can not serialize/deserialize all types, you can supply
a custom class to support types not directly supported by the JavaScriptSerializer
using the RegisterConverters method. A converter has to inherit from:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">abstract</span>
            <span style="COLOR: blue">class</span>
            <span style="COLOR: #2b91af">JavaScriptConverter</span>
          </p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">abstract</span><span style="COLOR: #2b91af">IEnumerable</span>&lt;<span style="COLOR: #2b91af">Type</span>&gt;
SupportedTypes
</p>
          <p style="MARGIN: 0px">
    {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">get</span>;
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">abstract</span><span style="COLOR: blue">object</span> Deserialize(<span style="COLOR: #2b91af">IDictionary</span>&lt;<span style="COLOR: blue">string</span>, <span style="COLOR: blue">object</span>&gt;
dictionary, <span style="COLOR: #2b91af">Type</span> type, <span style="COLOR: #2b91af">JavaScriptSerializer</span> serializer);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">abstract</span><span style="COLOR: #2b91af">IDictionary</span>&lt;<span style="COLOR: blue">string</span>, <span style="COLOR: blue">object</span>&gt;
Serialize(<span style="COLOR: blue">object</span> obj, <span style="COLOR: #2b91af">JavaScriptSerializer</span> serializer);
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
          <br />
    
<br /></p>
        <p>
and it has to implement the Serialize and Deserialize methods, as well as providing
the list of supported types.
</p>
        <p>
The standard MS AJAX distribution doesn't have any converter, but you can find a DataSet,
DataTable and DataRow converter in the ASP.NET AJAX Futures release.
</p>
        <p>
The other methods of the JavaScriptSerializer class are just serialize/deserialize
variants, and the ConvertToType method that will be explained later.
</p>
        <p>
The serialization of the basic types is as follows:
</p>
        <p>
null or DBNull.Value -&gt; "null"<br />
bool -&gt; "true" or "false"<br />
char -&gt; if it is '\0', "null", like a string if not<br />
float, double -&gt; ToString("r", CultureInfo.InvariantCulture)<br />
DateTime -&gt; "\/Date(number of milliseconds elapsed since midnight 1970/01/01 UTC)\/"<br />
string -&gt; quoted string<br />
Guid -&gt; "\" + ToString() + "\"<br />
Uri -&gt; "\" + Uri.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped)
+ "\"<br />
other primitive types and Decimal -&gt; IConvertible.ToString(CultureInfo.InvariantCulture)<br />
Enum -&gt; serialize the integer value of the enum<br />
IDictionary -&gt; JSON object<br />
IEnumerable -&gt; JSON array
</p>
        <p>
A custom object is serialized as a JSON object with the optional member "__type" :
typeName obtained using the JavaScriptResolver, where the other members are obtained
from the public instance fields and public instance properties without the ScriptIgnore
attribute applied.
</p>
        <p>
for more information about <a href="http://www.json.org/">JSON take a look here</a>.
</p>
        <p>
A Hashtable that compare references is used to throw an error if there is any circular
reference.
</p>
        <p>
Lets show an example of the serialization process. I'm going to use this User and
Address class:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <span style="COLOR: blue">
            <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
              <p style="MARGIN: 0px">
                <span style="COLOR: blue">public</span>
                <span style="COLOR: blue">class</span>
                <span style="COLOR: #2b91af">User</span>
              </p>
              <p style="MARGIN: 0px">
{
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">private</span><span style="COLOR: blue">int</span> _id;
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">private</span><span style="COLOR: blue">string</span> _name;
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">private</span><span style="COLOR: blue">string</span> _surName;
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">private</span><span style="COLOR: #2b91af">Address</span> _address;
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">private</span><span style="COLOR: #2b91af">DateTime</span> _creationDate;
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">int</span> ID
</p>
              <p style="MARGIN: 0px">
    {
</p>
              <p style="MARGIN: 0px">
        <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> _id;
}
</p>
              <p style="MARGIN: 0px">
        <span style="COLOR: blue">set</span> { _id = <span style="COLOR: blue">value</span>;
}
</p>
              <p style="MARGIN: 0px">
    }
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">string</span> Name
</p>
              <p style="MARGIN: 0px">
    {
</p>
              <p style="MARGIN: 0px">
        <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> _name;
}
</p>
              <p style="MARGIN: 0px">
        <span style="COLOR: blue">set</span> { _name
= <span style="COLOR: blue">value</span>; }
</p>
              <p style="MARGIN: 0px">
    }
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">string</span> SurName
</p>
              <p style="MARGIN: 0px">
    {
</p>
              <p style="MARGIN: 0px">
        <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> _surName;
}
</p>
              <p style="MARGIN: 0px">
        <span style="COLOR: blue">set</span> { _surName
= <span style="COLOR: blue">value</span>; }
</p>
              <p style="MARGIN: 0px">
    }
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
    [<span style="COLOR: #2b91af">ScriptIgnore</span>]
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">string</span> FullName
</p>
              <p style="MARGIN: 0px">
    {
</p>
              <p style="MARGIN: 0px">
        <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> Name
+ <span style="COLOR: #a31515">" "</span> + SurName; }
</p>
              <p style="MARGIN: 0px">
    }
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: #2b91af">Address</span> Address
</p>
              <p style="MARGIN: 0px">
    {
</p>
              <p style="MARGIN: 0px">
        <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> _address;
}
</p>
              <p style="MARGIN: 0px">
        <span style="COLOR: blue">set</span> { _address
= <span style="COLOR: blue">value</span>; }
</p>
              <p style="MARGIN: 0px">
    }
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: #2b91af">DateTime</span> CreationDate
</p>
              <p style="MARGIN: 0px">
    {
</p>
              <p style="MARGIN: 0px">
        <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> _creationDate;
}
</p>
              <p style="MARGIN: 0px">
        <span style="COLOR: blue">set</span> { _creationDate
= <span style="COLOR: blue">value</span>; }
</p>
              <p style="MARGIN: 0px">
    }
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> User()
</p>
              <p style="MARGIN: 0px">
    {
</p>
              <p style="MARGIN: 0px">
    }
</p>
              <p style="MARGIN: 0px">
}
</p>
              <p style="MARGIN: 0px">
 
</p>
            </div>
            <!--EndFragment-->
          </span>
        </div>
        <!--EndFragment-->
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">class</span>
            <span style="COLOR: #2b91af">Address</span>
          </p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">private</span><span style="COLOR: blue">string</span> _firstLine;
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">private</span><span style="COLOR: blue">string</span> _secondLine;
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">private</span><span style="COLOR: blue">string</span> _country;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">string</span> FirstLine
</p>
          <p style="MARGIN: 0px">
    {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> _firstLine;
}
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">set</span> { _firstLine
= <span style="COLOR: blue">value</span>; }
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">string</span> SecondLine
</p>
          <p style="MARGIN: 0px">
    {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> _secondLine;
}
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">set</span> { _secondLine
= <span style="COLOR: blue">value</span>; }
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">string</span> Country
</p>
          <p style="MARGIN: 0px">
    {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> _country;
}
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">set</span> { _country
= <span style="COLOR: blue">value</span>; }
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> Address()
</p>
          <p style="MARGIN: 0px">
    {
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
With the following code:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">JavaScriptSerializer</span> js = <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">JavaScriptSerializer</span>(<span style="COLOR: blue">new</span><span style="COLOR: #2b91af">SimpleTypeResolver</span>());
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">User</span> usr = <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">User</span>();
</p>
          <p style="MARGIN: 0px">
usr.ID = 12345;
</p>
          <p style="MARGIN: 0px">
usr.Name = <span style="COLOR: #a31515">"John"</span>;
</p>
          <p style="MARGIN: 0px">
usr.SurName = <span style="COLOR: #a31515">"Smith"</span>;
</p>
          <p style="MARGIN: 0px">
usr.Address = <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">Address</span>();
</p>
          <p style="MARGIN: 0px">
usr.Address.FirstLine = <span style="COLOR: #a31515">"1st Avenue, 1234"</span>;
</p>
          <p style="MARGIN: 0px">
usr.Address.SecondLine = <span style="COLOR: #a31515">"San Diego, CA 92101"</span>;
</p>
          <p style="MARGIN: 0px">
usr.CreationDate = <span style="COLOR: #2b91af">DateTime</span>.Now;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">string</span> str = js.Serialize(usr);
</p>
        </div>
        <p>
          <!--EndFragment-->  <br /></p>
        <p>
The SimpleTypeResolver inherits from the JavaScriptTypeResolver class explained before,
converting a Type a string using the AssemblyQualifiedName and viceversa.
</p>
        <p>
Is serialized as:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: #a31515">"__type"</span>:<span style="COLOR: #a31515">"User,
AJAXServerSide1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"</span>,
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: #a31515">"ID"</span>:12345,
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: #a31515">"Name"</span>:<span style="COLOR: #a31515">"John"</span>,
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: #a31515">"SurName"</span>:<span style="COLOR: #a31515">"Smith"<font color="#000000">,</font></span><span style="COLOR: #a31515"></span></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: #a31515">"Address"</span>:
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #a31515">"__type"</span>:<span style="COLOR: #a31515">"Address,
AJAXServerSide1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"</span>,
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #a31515">"FirstLine"</span>:<span style="COLOR: #a31515">"1st
Avenue, 1234"</span>,
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #a31515">"SecondLine"</span>:<span style="COLOR: #a31515">"San
Diego, CA 92101"</span>,
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #a31515">"Country"</span>:<span style="COLOR: blue">null</span></p>
          <p style="MARGIN: 0px">
        }<font color="#000000">,</font></p>
          <p style="MARGIN: 0px">
    <span style="COLOR: #a31515">"CreationDate"</span><font color="#000000">:</font><span style="COLOR: #a31515">"\/Date(1173541909382)\/"</span></p>
          <p style="MARGIN: 0px">
} 
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
Note that the FullName property of the User is not serialized because the ScriptIgnore
attribute.
</p>
        <p>
The deserialization process is delegated to the JavaScriptObjectDeserializer class.
This class uses the JavaScriptString and the ObjectConverter class. The JavaScriptString
class is a helper class used to tokenize the JSON data. As when the data is serialized
all types are converted to JSON types (strings, numbers, JSON objects and JSON arrays)
some kind of conversion back to the original type must take place. The JavaScriptObjectDeserializer
does some simple conversions like checking if a string is a character, a boolean,
a date or a null value, most significant conversions are handled by the ConvertObjectToTypeInternal
method of the ObjectConverter class. 
</p>
        <p>
The ConvertObjectToTypeInternal uses the __type field, source object type and destination
type to perform the convertion. If the source data is of type IDictionary it tries
to create an object of the destination type and sets its fields and properties with
the values stored in the dictionary. If the source data is of type IList, it tries
to create a collection of the destination type and adds each of the items of the list
to the collection. If the collection is a generic collection, it extract the item
type of the collection and tries to convert the items as they're added to the collection.
</p>
        <p>
If the source type isn't neither an IDictionary nor an IList, it gets the TypeConverter
for the destination type and check if the source data can be converted to that type.
If the source type doesn't have a conversion to the destination type, it converts
the source type to a string and then tries to convert that string to the destination
type (all of the conversion that involve the TypeConverter use the InvariantCulture). 
</p>
        <p>
If everything fails, a conversion exception is thrown. 
</p>
        <p>
To continue the previous example, this converts the string obtained from the Serialize
method back to an User instance:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">User</span> u = js.Deserialize&lt;User&gt;(str);
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
 
</p>
        <p>
When comparing the initial User instance with the deserialized one, the CreationDate
is different by one hour (at least in my machine), so there is a bug in the MS AJAX
code that handles DateTimes :-(
</p>
        <p>
One curious thing about serialization is that the property names are case insensitive
when deserializing an object, as the AssignToPropertyOrField method uses the BindingFlags.IgnoreCase
to retrieve properties and fields. However, when an object is serialized, the properties
for the client code are case sensitive.
</p>
        <p>
I have run out of time for this week but soon I'll continue with the internals of
the additions of MS AJAX to the web.config.
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=22a125d3-1ed3-422b-ba2b-89ed63febce3" />
      </body>
      <title>ASP.NET AJAX Extensions Internals - Web.Config and Serialization</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,22a125d3-1ed3-422b-ba2b-89ed63febce3.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,22a125d3-1ed3-422b-ba2b-89ed63febce3.aspx</link>
      <pubDate>Sun, 11 Mar 2007 18:10:25 GMT</pubDate>
      <description>&lt;p&gt;
Some time ago I started bloging about the Client Side OOP Features of Atlas (now the
Microsoft AJAX Library. The posts are &lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,c59facc0-301e-4e30-898d-428038828dcd.aspx"&gt;here&lt;/a&gt; and &lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,e440e756-b3fa-4ec2-aea7-f2f28dee1a38.aspx"&gt;here&lt;/a&gt;). 
&lt;/p&gt;
&lt;p&gt;
As I think that most ASP.NET developers will use mainly the server side AJAX extensions
I'll start covering the internals of the server side additions to ASP.NET to support
AJAX.
&lt;/p&gt;
&lt;p&gt;
If you create a new Web Site in VS2005 using the "ASP.NET AJAX Enabled Web-Site" you'll
see that the web.config file for this web has quite a few additions to the default
one related to AJAX. The additions to the web.config are:
&lt;/p&gt;
&lt;p&gt;
1) Added some custom sections handlers to configure the new AJAX features 
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sectionGroup&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;system.web.extensions&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;System.Web.Configuration.SystemWebExtensionsSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sectionGroup&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;scripting&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;System.Web.Configuration.ScriptingSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;section&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;scriptResourceHandler&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;System.Web.Configuration.ScriptingScriptResourceHandlerSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;requirePermission&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;false&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;allowDefinition&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;MachineToApplication&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sectionGroup&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;webServices&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;System.Web.Configuration.ScriptingWebServicesSectionGroup,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;section&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;jsonSerialization&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;System.Web.Configuration.ScriptingJsonSerializationSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;requirePermission&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;false&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;allowDefinition&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;Everywhere&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;section&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;profileService&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;System.Web.Configuration.ScriptingProfileServiceSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;requirePermission&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;false&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;allowDefinition&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;MachineToApplication&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;section&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;authenticationService&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;System.Web.Configuration.ScriptingAuthenticationServiceSection,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;requirePermission&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;false&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;allowDefinition&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;MachineToApplication&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sectionGroup&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sectionGroup&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;sectionGroup&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
2) Configured the "asp" tag prefix for controls in the AJAX implementation assembly:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;pages&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;controls&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;add&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;tagPrefix&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;asp&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;namespace&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;System.Web.UI&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;assembly&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;controls&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;pages&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
3) Added the AJAX assembly reference to the compilation process:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;compilation&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;debug&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;false&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;assemblies&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;add&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;assembly&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;assemblies&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;compilation&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
4) Modified the HTTP Handlers:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;httpHandlers&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;remove&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;verb&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;*&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;path&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;*.asmx&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;add&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;verb&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;*&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;path&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;*.asmx&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;validate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;false&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;add&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;verb&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;*&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;path&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;*_AppService.axd&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;validate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;false&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;add&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;verb&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;GET,HEAD&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;path&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;ScriptResource.axd&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;System.Web.Handlers.ScriptResourceHandler,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;validate&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;false&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;httpHandlers&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
5) Added an HTTP Module:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;httpModules&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;add&lt;/span&gt;&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;name&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;ScriptModule&lt;/span&gt;"&lt;span style="COLOR: blue"&gt; &lt;/span&gt;&lt;span style="COLOR: red"&gt;type&lt;/span&gt;&lt;span style="COLOR: blue"&gt;=&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&lt;/span&gt;"&lt;span style="COLOR: blue"&gt;/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;httpModules&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
6) Added the configuration sections to configure ASP.NET AJAX (the section handlers
were registered previously as explained in point 1).
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;system.web.extensions&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;scripting&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;webServices&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;!--&lt;/span&gt;&lt;span style="COLOR: green"&gt; Uncomment
this line to customize maxJsonLength and add a custom converter &lt;/span&gt;&lt;span style="COLOR: blue"&gt;--&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;!--&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;jsonSerialization maxJsonLength="500"&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;converters&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;add name="ConvertMe"
type="Acme.SubAcme.ConvertMeTypeConverter"/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/converters&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/jsonSerialization&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;--&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;!--&lt;/span&gt;&lt;span style="COLOR: green"&gt; Uncomment
this line to enable the authentication service. Include requireSSL="true" if appropriate. &lt;/span&gt;&lt;span style="COLOR: blue"&gt;--&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;!--&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;authenticationService enabled="true"
requireSSL = "true|false"/&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;--&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;!--&lt;/span&gt;&lt;span style="COLOR: green"&gt; Uncomment
these lines to enable the profile service. To allow profile properties to be retrieved&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; and modified in ASP.NET
AJAX applications, you need to add each property name to the readAccessProperties
and&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; writeAccessProperties
attributes. &lt;/span&gt;&lt;span style="COLOR: blue"&gt;--&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;!--&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;profileService enabled="true"&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; readAccessProperties="propertyname1,propertyname2"&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;nbsp; writeAccessProperties="propertyname1,propertyname2" /&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;--&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;webServices&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;!--&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;scriptResourceHandler enableCompression="true"
enableCaching="true" /&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: green"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span style="COLOR: blue"&gt;--&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;scripting&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp; &amp;lt;/&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;system.web.extensions&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&lt;br&gt;
&amp;nbsp; 
&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
The most important additions to the web.config to support the Microsoft ASP.NET AJAX
Extensions (MS AJAX from now on) are point 4 and 5. As the ASP.NET HTTP pipeline is
very configurable, those additions can have severe implications on how request are
handled, so I'll start with them.
&lt;/p&gt;
&lt;p&gt;
In the HTTP handlers section, the first line removes the default handling for the
asmx extension, and the second one registers a new handler for the asmx extension.
This simple changes makes that any call to a web service doesn't work as we are used
to. The asmx requests now will go through the ScriptHandlerFactory.
&lt;/p&gt;
&lt;p&gt;
Usually in the HTTP handlers session we register a class that implements the IHttpHanlder
interface. The ProcessRequest method will be called to do all processing. 
&lt;/p&gt;
&lt;p&gt;
However, we can also register a class that implements an IHttpHandlerFactory. In this
case, the method GetHandler will be called in the factory, returning an IHttpHandler
that will handle the request. This is used when you want to return different IHttpHandler
instances depending on some conditions of the request.
&lt;/p&gt;
&lt;p&gt;
When a request that is handled by the ScriptHandlerFactory arrives, it checks if the
request is a REST request (REST is a way to transmit data over HTTP without using
any additional messaging layer. Consult &lt;a href="http://en.wikipedia.org/wiki/REST"&gt;wikipedia&lt;/a&gt; for
more information about it). If it is a REST request, the RestHandlerFactory (a MS
AJAX class) will take care of the request. If it isn't, the WebServiceHandlerFactory
will take care of it. Probably the class WebServiceHandlerFactory won't say much to
you, but this is the class that handles ASMX request in the ASP.NET 2.0, so when an
ASMX request isn't a REST request, it is handled in the same way as we're used to.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
What is a REST request for MS AJAX? A REST request is an HTTP request that has the
ContentType property set to "application/json" (this is called a REST method request)
or an HTTP request whose path ends with "/js" or "/jsdebug" (this is called a REST
client proxy request).
&lt;/p&gt;
&lt;p&gt;
The RestHandlerFactory checks if the request is for a client proxy or for a REST method.
If the request is for a client proxy, a RestClientProxyHandler is created and servers
the request. The RestClientProxyHandler figures which client proxy has been requested,
gets the client proxy and sends it. All the hard work is done by the WebServiceClientProxyGenerator.GetClientProxyScript
method. Before entering in detail how the client script proxy is generated, lets see
how MS AJAX handles serialization.
&lt;/p&gt;
&lt;p&gt;
Data types are exchanged between client side and server side using JSON (JavaScript
Object Notation). To send data to the client side from the server, the data is serialized,
and to receive it from the client, the data is deserialized in the server.
&lt;/p&gt;
&lt;p&gt;
The main class responsible for this serialization/deserialization process is JavaScriptSerializer.
The public member for the class are:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;JavaScriptSerializer&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; JavaScriptSerializer();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; JavaScriptSerializer(&lt;span style="COLOR: #2b91af"&gt;JavaScriptTypeResolver&lt;/span&gt; resolver);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; MaxJsonLength
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; RecursionLimit
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Serialize(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; obj);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Serialize(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; obj, &lt;span style="COLOR: #2b91af"&gt;StringBuilder&lt;/span&gt; output);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; T Deserialize&amp;lt;T&amp;gt;(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; input);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; DeserializeObject(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; input);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; T ConvertToType&amp;lt;T&amp;gt;(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; obj);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; RegisterConverters(IEnumerable&amp;lt;&lt;span style="COLOR: #2b91af"&gt;JavaScriptConverter&lt;/span&gt;&amp;gt;
converters);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
The serialization fails if there are more nested objects than RecursionLimit or if
the length of the serialized object is MaxJsonLength.
&lt;/p&gt;
&lt;p&gt;
A serialized object can optionally include type information. The type information
is provided by a class that inherits from JavaScriptTypeResolver, that has the following
methods to get a type from a string and viceversa: 
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;JavaScriptTypeResolver&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Type&lt;/span&gt; ResolveType(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; id);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; ResolveTypeId(&lt;span style="COLOR: #2b91af"&gt;Type&lt;/span&gt; type);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The serializer will add the type information in a field called __type if it has an
associated JavaScriptTypeResolver.
&lt;/p&gt;
&lt;p&gt;
As the JavaScriptSerializer can not serialize/deserialize all types, you can supply
a custom class to support types not directly supported by the JavaScriptSerializer
using the RegisterConverters method. A converter has to inherit from:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;JavaScriptConverter&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="COLOR: #2b91af"&gt;Type&lt;/span&gt;&amp;gt;
SupportedTypes
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; Deserialize(&lt;span style="COLOR: #2b91af"&gt;IDictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;object&lt;/span&gt;&amp;gt;
dictionary, &lt;span style="COLOR: #2b91af"&gt;Type&lt;/span&gt; type, &lt;span style="COLOR: #2b91af"&gt;JavaScriptSerializer&lt;/span&gt; serializer);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;IDictionary&lt;/span&gt;&amp;lt;&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;object&lt;/span&gt;&amp;gt;
Serialize(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; obj, &lt;span style="COLOR: #2b91af"&gt;JavaScriptSerializer&lt;/span&gt; serializer);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
and it has to implement the Serialize and Deserialize methods, as well as providing
the list of supported types.
&lt;/p&gt;
&lt;p&gt;
The standard MS AJAX distribution doesn't have any converter, but you can find a DataSet,
DataTable and DataRow converter in the ASP.NET AJAX Futures release.
&lt;/p&gt;
&lt;p&gt;
The other methods of the JavaScriptSerializer class are just serialize/deserialize
variants, and the ConvertToType method that will be explained later.
&lt;/p&gt;
&lt;p&gt;
The serialization of the basic types is as follows:
&lt;/p&gt;
&lt;p&gt;
null or DBNull.Value -&amp;gt; "null"&lt;br&gt;
bool -&amp;gt; "true" or "false"&lt;br&gt;
char -&amp;gt; if it is '\0', "null", like a string if not&lt;br&gt;
float, double -&amp;gt; ToString("r", CultureInfo.InvariantCulture)&lt;br&gt;
DateTime -&amp;gt; "\/Date(number of milliseconds elapsed since midnight 1970/01/01 UTC)\/"&lt;br&gt;
string -&amp;gt; quoted string&lt;br&gt;
Guid -&amp;gt; "\" + ToString() + "\"&lt;br&gt;
Uri -&amp;gt; "\" + Uri.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped)
+ "\"&lt;br&gt;
other primitive types and Decimal -&amp;gt; IConvertible.ToString(CultureInfo.InvariantCulture)&lt;br&gt;
Enum -&amp;gt; serialize the integer value of the enum&lt;br&gt;
IDictionary -&amp;gt; JSON object&lt;br&gt;
IEnumerable -&amp;gt; JSON array
&lt;/p&gt;
&lt;p&gt;
A custom object is serialized as a JSON object with the optional member "__type" :
typeName obtained using the JavaScriptResolver, where the other members are obtained
from the public instance fields and public instance properties without the ScriptIgnore
attribute applied.
&lt;/p&gt;
&lt;p&gt;
for more information about &lt;a href="http://www.json.org/"&gt;JSON take a look here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
A Hashtable that compare references is used to throw an error if there is any circular
reference.
&lt;/p&gt;
&lt;p&gt;
Lets show an example of the serialization process. I'm going to use this User and
Address class:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;User&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; _id;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; _name;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; _surName;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Address&lt;/span&gt; _address;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DateTime&lt;/span&gt; _creationDate;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; ID
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _id;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; { _id = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Name
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _name;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; { _name
= &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; SurName
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _surName;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; { _surName
= &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="COLOR: #2b91af"&gt;ScriptIgnore&lt;/span&gt;]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; FullName
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; Name
+ &lt;span style="COLOR: #a31515"&gt;" "&lt;/span&gt; + SurName; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Address&lt;/span&gt; Address
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _address;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; { _address
= &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DateTime&lt;/span&gt; CreationDate
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _creationDate;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; { _creationDate
= &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; User()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Address&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; _firstLine;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; _secondLine;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; _country;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; FirstLine
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _firstLine;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; { _firstLine
= &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; SecondLine
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _secondLine;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; { _secondLine
= &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; Country
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; _country;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; { _country
= &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; Address()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
With the following code:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;JavaScriptSerializer&lt;/span&gt; js = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;JavaScriptSerializer&lt;/span&gt;(&lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SimpleTypeResolver&lt;/span&gt;());
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;User&lt;/span&gt; usr = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;User&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
usr.ID = 12345;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
usr.Name = &lt;span style="COLOR: #a31515"&gt;"John"&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
usr.SurName = &lt;span style="COLOR: #a31515"&gt;"Smith"&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
usr.Address = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Address&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
usr.Address.FirstLine = &lt;span style="COLOR: #a31515"&gt;"1st Avenue, 1234"&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
usr.Address.SecondLine = &lt;span style="COLOR: #a31515"&gt;"San Diego, CA 92101"&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
usr.CreationDate = &lt;span style="COLOR: #2b91af"&gt;DateTime&lt;/span&gt;.Now;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; str = js.Serialize(usr);
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
The SimpleTypeResolver inherits from the JavaScriptTypeResolver class explained before,
converting a Type a string using the AssemblyQualifiedName and viceversa.
&lt;/p&gt;
&lt;p&gt;
Is serialized as:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #a31515"&gt;"__type"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"User,
AJAXServerSide1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="COLOR: #a31515"&gt;"ID"&lt;/span&gt;:12345,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #a31515"&gt;"Name"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"John"&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #a31515"&gt;"SurName"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"Smith"&lt;font color=#000000&gt;,&lt;/font&gt;&lt;/span&gt;&lt;span style="COLOR: #a31515"&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #a31515"&gt;"Address"&lt;/span&gt;:
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #a31515"&gt;"__type"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"Address,
AJAXServerSide1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #a31515"&gt;"FirstLine"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"1st
Avenue, 1234"&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #a31515"&gt;"SecondLine"&lt;/span&gt;:&lt;span style="COLOR: #a31515"&gt;"San
Diego, CA 92101"&lt;/span&gt;,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #a31515"&gt;"Country"&lt;/span&gt;:&lt;span style="COLOR: blue"&gt;null&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;font color=#000000&gt;,&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #a31515"&gt;"CreationDate"&lt;/span&gt;&lt;font color=#000000&gt;:&lt;/font&gt;&lt;span style="COLOR: #a31515"&gt;"\/Date(1173541909382)\/"&lt;/span&gt;
&lt;/p&gt;
&gt; 
&lt;p style="MARGIN: 0px"&gt;
} 
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Note that the FullName property of the User is not serialized because the ScriptIgnore
attribute.
&lt;/p&gt;
&lt;p&gt;
The deserialization process is delegated to the JavaScriptObjectDeserializer class.
This class uses the JavaScriptString and the ObjectConverter class. The JavaScriptString
class is a helper class used to tokenize the JSON data. As when the data is serialized
all types are converted to JSON types (strings, numbers, JSON objects and JSON arrays)
some kind of conversion back to the original type must take place. The JavaScriptObjectDeserializer
does some simple conversions like checking if a string is a character, a boolean,
a date or a null value, most significant conversions are handled by the ConvertObjectToTypeInternal
method of the ObjectConverter class. 
&lt;/p&gt;
&lt;p&gt;
The ConvertObjectToTypeInternal uses the __type field, source object type and destination
type to perform the convertion. If the source data is of type IDictionary it tries
to create an object of the destination type and sets its fields and properties with
the values stored in the dictionary. If the source data is of type IList, it tries
to create a collection of the destination type and adds each of the items of the list
to the collection. If the collection is a generic collection, it extract the item
type of the collection and tries to convert the items as they're added to the collection.
&lt;/p&gt;
&lt;p&gt;
If the source type isn't neither an IDictionary nor an IList, it gets the TypeConverter
for the destination type and check if the source data can be converted to that type.
If the source type doesn't have a conversion to the destination type, it converts
the source type to a string and then tries to convert that string to the destination
type (all of the conversion that involve the TypeConverter use the InvariantCulture). 
&lt;/p&gt;
&lt;p&gt;
If everything fails, a conversion exception is thrown. 
&lt;/p&gt;
&lt;p&gt;
To continue the previous example, this converts the string obtained from the Serialize
method back to an User instance:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;User&lt;/span&gt; u = js.Deserialize&amp;lt;User&amp;gt;(str);
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
When comparing the initial User instance with the deserialized one, the CreationDate
is different by one hour (at least in my machine), so there is a bug in the MS AJAX
code that handles DateTimes :-(
&lt;/p&gt;
&lt;p&gt;
One curious thing about serialization is that the property names are case insensitive
when deserializing an object, as the AssignToPropertyOrField method uses the BindingFlags.IgnoreCase
to retrieve properties and fields. However, when an object is serialized, the properties
for the client code are case sensitive.
&lt;/p&gt;
&lt;p&gt;
I have run out of time for this week but soon I'll continue with the internals of
the additions of MS AJAX to the web.config.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=22a125d3-1ed3-422b-ba2b-89ed63febce3" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,22a125d3-1ed3-422b-ba2b-89ed63febce3.aspx</comments>
      <category>Ajax;ASP.NET;JavaScript</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=c8f39803-b507-4449-919a-462198a80645</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,c8f39803-b507-4449-919a-462198a80645.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,c8f39803-b507-4449-919a-462198a80645.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=c8f39803-b507-4449-919a-462198a80645</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>Microsoft ASP.NET AJAX v1.0 released!</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,c8f39803-b507-4449-919a-462198a80645.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,c8f39803-b507-4449-919a-462198a80645.aspx</link>
      <pubDate>Wed, 24 Jan 2007 17:17:12 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Finally the Microsoft AJAX library
1.0 has been released. Take a look to ScottGu's blog for&amp;nbsp;the details:&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/01/23/asp-net-ajax-1-0-released.aspx"&gt;http://weblogs.asp.net/scottgu/archive/2007/01/23/asp-net-ajax-1-0-released.aspx&lt;/a&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;What
is really cool about this is that Microsoft has also released the full source code
for the 
&lt;st1:place w:st="on"&gt;
&lt;st1:City w:st="on"&gt;AJAX&lt;/st1:City&gt;
&lt;/st1:place&gt;
library. That move can give a lot of people that do not work with Microsoft related
technologies a reason to try it and use it, and for the rest of us a chance to take
a look to some of the internals if it is needed.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;It is a shame that some parts of
the initial ATLAS library like the Bindings didn’t make it in the final release. Anyway,
they’re available in the AJAX Futures CTP and someday will be part of the official
release.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Will this mean that we will see
a lot of .NET developers working directly with the Microsoft AJAX library? IMHO, no.
Probably most developers will use the Ajax Control Toolkit and the UpdatePanel to
add 
&lt;st1:place w:st="on"&gt;
&lt;st1:City w:st="on"&gt;AJAX&lt;/st1:City&gt;
&lt;/st1:place&gt;
capabilities to their projects. 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Creating ASP.NET components that
make use the client side of the Microsoft AJAX library is not easy: You need to know
quite a bunch of stuff: a .NET programming language, ASP.NET, Javascript, HTML, DHTML,
CSS, XML and AJAX Library internals… so I guess a lot of developers are out of luck.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Fortunately, Nikhil’s Script# can
help a bit, and finally changed the type system to be compatible with the AJAX Library
(I asked Nikhil about this a few months ago and I wasn’t sure that he will do it,
but I’m glad he did!).&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Also, there is a lot of other new
stuff to look as a .NET developer: WPF, WCF, WF, LINQ, DLINQ, WPF/E. And if you’re
using SQL Server 2005, there are a lot of new things to look at…&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0cm 0cm 0pt"&gt;
&lt;span lang=EN-GB style="mso-ansi-language: EN-GB"&gt;Personally I have to learn the Microsoft
AJAX Library in detail but I’m also interested in learning Windows Workflow Foundation,
so I’m not sure in what to center my attention at the moment.&lt;/span&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=c8f39803-b507-4449-919a-462198a80645" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,c8f39803-b507-4449-919a-462198a80645.aspx</comments>
      <category>Ajax;ASP.NET;JavaScript;Microsoft .NET Framework;WPF/E</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=1981d708-5949-4d87-b7f4-ae60df47b298</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,1981d708-5949-4d87-b7f4-ae60df47b298.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,1981d708-5949-4d87-b7f4-ae60df47b298.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=1981d708-5949-4d87-b7f4-ae60df47b298</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Another year ends and a new one comes. Life goes as fast as usual and we’re keep
on our way. It’s time to think about it… our actions, hopes, wishes, mistakes,
etc. 
</p>
        <p>
I usually listen to a special song a few minutes after the start of the year.
In the last few years I have been choosing "Aerosmith – Full Circle" because it has
special connotations for me. 
</p>
        <p>
I wish you the best in the coming year.
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=1981d708-5949-4d87-b7f4-ae60df47b298" />
      </body>
      <title>Happy 2007!</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,1981d708-5949-4d87-b7f4-ae60df47b298.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,1981d708-5949-4d87-b7f4-ae60df47b298.aspx</link>
      <pubDate>Mon, 01 Jan 2007 23:36:54 GMT</pubDate>
      <description>&lt;p&gt;
Another year ends and a new one comes. Life goes as fast as usual and we’re&amp;nbsp;keep
on&amp;nbsp;our way. It’s time to think about it… our actions, hopes, wishes, mistakes,
etc. 
&lt;/p&gt;
&lt;p&gt;
I usually listen to a special song&amp;nbsp;a few minutes after the start of the year.
In the last few years I have been choosing "Aerosmith – Full Circle" because it has
special connotations for me. 
&lt;/p&gt;
&lt;p&gt;
I wish you the best in the coming year.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=1981d708-5949-4d87-b7f4-ae60df47b298" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,1981d708-5949-4d87-b7f4-ae60df47b298.aspx</comments>
      <category>Ajax;ANTLR;ASP.NET;CSS;Games;General;JavaScript;Microsoft .NET Framework;Music;WPF/E</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=23bf78a6-e5b3-441f-9b89-e500b5c787c7</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,23bf78a6-e5b3-441f-9b89-e500b5c787c7.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,23bf78a6-e5b3-441f-9b89-e500b5c787c7.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=23bf78a6-e5b3-441f-9b89-e500b5c787c7</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have spent most of the last weeks changing some designs to use pure CSS layouts
instead of table based designs and having to support IE 5.0+.  So you can imagine
my frustation level. It’s really sad to see the required work to make a complex design
work in IE 5.0, IE 5.5 MAC IE 5, IE 6, IE 7, Firefox, Safari and Opera. IE versions
prior to IE 6 are really terrible in CSS compliance and you need to have solid IE
bug theory to fix those limitations. 
</p>
        <p>
It is really sad that here (in Spain) and maybe in other countries too, there are
still a significative percentage of users using IE 5.0 and IE 5.5. IMO there should
be some kind of movement to delete old browsers from the earth. For example, in Europe
there will be an analogic TV shutdown before 2012. There should be something similar
periodically for old browsers. For example every year most of the webpages should
use an updated script to completely fail in browsers older than 2 or 3 years, forcing
the people to upgrade because most of the webpages they visit will not work for them
(as some people will only upgrade for that reason).
</p>
        <p>
Talking about browsers, it is sad to see that IE 7 does not pass the ACID2 tests.
Also Firefox, the browser that claimed to be more standard compliant than IE and that
will save our souls, doesn’t pass the ACID2 tests either (in the 2.0 release). The
first version of Firefox was very good compared to the browsers out there but now
they haven’t improved it very much lately. Anyway, the developer extensions for firefox
are so good that it is a must have. I was very surprised with Opera 9 because it passed
ACID2 tests, has finally added support for rich text editing so things like R.A.D.
editor (<a href="http://www.telerik.com">www.telerik.com</a>) finally works and it
has an excellent zoom tool, not like the Firefox one that the only thing that does
is to break all pages when you zoom a bit.
</p>
        <p>
But to be fair, a big part of the problems are because of the lack of a reference
implementation by the W3C. CSS will be better designed and more trouble free with
a reference implementation so the people defining and implementing the standard can
play with. It won’t be too difficult to produce automated tests to compare rendered
web pages with different implementations of the standard using a common set of stylesheets
and fonts, so a pixel perfect comparision will be possible if the rendering engines
do not employ any dithering. Having a reference implementation to play with will also
help in making a more robust and useful specification (why is so complex to align
something vertically in CSS when aligning it horizontally is trivial?).
</p>
        <p>
Will this situation change some day? It is changing slowly but with some help it will
be able to change faster and let us focus in real problems and not in stupid incompatibility
problems that only causes us headaches and slow down web evolution.
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=23bf78a6-e5b3-441f-9b89-e500b5c787c7" />
      </body>
      <title>*&amp;&amp;$&amp;# CSS incompatibilities</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,23bf78a6-e5b3-441f-9b89-e500b5c787c7.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,23bf78a6-e5b3-441f-9b89-e500b5c787c7.aspx</link>
      <pubDate>Fri, 27 Oct 2006 23:34:44 GMT</pubDate>
      <description>&lt;p&gt;
I have spent most of the last weeks changing some designs to use pure CSS layouts
instead of table based designs and having to support IE 5.0+.&amp;nbsp; So you can imagine
my frustation level. It’s really sad to see the required work to make a complex design
work in IE 5.0, IE 5.5 MAC IE 5, IE 6, IE 7, Firefox, Safari and Opera. IE versions
prior to IE 6 are really terrible in CSS compliance and you need to have solid IE
bug theory to fix those limitations. 
&lt;/p&gt;
&lt;p&gt;
It is really sad that here (in Spain) and maybe in other countries too, there are
still a significative percentage of users using IE 5.0 and IE 5.5. IMO there should
be some kind of movement to delete old browsers from the earth. For example, in Europe
there will be an analogic TV shutdown before 2012. There should be something similar
periodically for old browsers. For example every year most of the webpages should
use an updated script to completely fail in browsers older than 2 or 3 years, forcing
the people to upgrade because most of the webpages they visit will not work for them
(as some people will only upgrade for that reason).
&lt;/p&gt;
&lt;p&gt;
Talking about browsers, it is sad to see that IE 7 does not pass the ACID2 tests.
Also Firefox, the browser that claimed to be more standard compliant than IE and that
will save our souls, doesn’t pass the ACID2 tests either (in the 2.0 release). The
first version of Firefox was very good compared to the browsers out there but now
they haven’t improved it very much lately. Anyway, the developer extensions for firefox
are so good that it is a must have. I was very surprised with Opera 9 because it passed
ACID2 tests, has finally added support for rich text editing so things like R.A.D.
editor (&lt;a href="http://www.telerik.com"&gt;www.telerik.com&lt;/a&gt;) finally works and it
has an excellent zoom tool, not like the Firefox one that the only thing that does
is to break all pages when you zoom a bit.
&lt;/p&gt;
&lt;p&gt;
But to be fair, a big part of the problems are because of the lack of a reference
implementation by the W3C. CSS will be better designed and more trouble free with
a reference implementation so the people defining and implementing the standard can
play with. It won’t be too difficult to produce automated tests to compare rendered
web pages with different implementations of the standard using a common set of stylesheets
and fonts, so a pixel perfect comparision will be possible if the rendering engines
do not employ any dithering. Having a reference implementation to play with will also
help in making a more robust and useful specification (why is so&amp;nbsp;complex to align
something vertically in CSS when aligning it horizontally is trivial?).
&lt;/p&gt;
&lt;p&gt;
Will this situation change some day? It is changing slowly but with some help it will
be able to change faster and let us focus in real problems and not in stupid incompatibility
problems that only causes us headaches and slow down web evolution.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=23bf78a6-e5b3-441f-9b89-e500b5c787c7" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,23bf78a6-e5b3-441f-9b89-e500b5c787c7.aspx</comments>
      <category>Ajax;ASP.NET;CSS;JavaScript</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=e440e756-b3fa-4ec2-aea7-f2f28dee1a38</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,e440e756-b3fa-4ec2-aea7-f2f28dee1a38.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,e440e756-b3fa-4ec2-aea7-f2f28dee1a38.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=e440e756-b3fa-4ec2-aea7-f2f28dee1a38</wfw:commentRss>
      <slash:comments>5</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Note: Bertrand Le Roy has confirmed that the next Microsoft AJAX Library release will
use the prototype based approach instead of the closure approach (really great news!),
and clearly explains the differences:
</p>
        <p>
          <a href="http://weblogs.asp.net/bleroy/archive/2006/10/11/From-closures-to-prototypes_2C00_-part-1.aspx">http://weblogs.asp.net/bleroy/archive/2006/10/11/From-closures-to-prototypes_2C00_-part-1.aspx</a>
        </p>
        <p>
In <a href="http://www.manuelabadia.com/blog/PermaLink,guid,c59facc0-301e-4e30-898d-428038828dcd.aspx">part
1</a> we saw how the inheritance infrastructure worked, how to create namespaces,
and how to create classes. Now it is time to continue with the other stuff.
</p>
        <p>
          <strong>Interfaces</strong>
        </p>
        <p>
To create an interface is similar to create a class, but we use the registerInterface
method instead and we define the methods to be abstract. For example:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.MyInterface = <span style="COLOR: blue">function</span>() {
</p>
          <p style="MARGIN: 0px">
   <span style="COLOR: blue">this</span>.method1 = Function.abstractMethod;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.MyInterface.registerInterface(<span style="COLOR: maroon">'Manu.Atlas.Tests.MyInterface'</span>);
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
We can define the interface using the prototype method instead of the closure method:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
            <p style="MARGIN: 0px">
Manu.Atlas.Tests.MyInterface = <span style="COLOR: blue">function</span>() {
</p>
            <p style="MARGIN: 0px">
}
</p>
            <p style="MARGIN: 0px">
 
</p>
            <p style="MARGIN: 0px">
Manu.Atlas.Tests.MyInterface.prototype.method1 = Function.abstractMethod;
</p>
            <p style="MARGIN: 0px">
 
</p>
            <p style="MARGIN: 0px">
Manu.Atlas.Tests.MyInterface.registerInterface(<span style="COLOR: maroon">'Manu.Atlas.Tests.MyInterface'</span>);
</p>
          </div>
          <!--EndFragment-->
        </div>
        <p>
 
</p>
        <p>
The registerInterface method (defined in the Function type) just set the _typeName
of the type where the method is invoked, and sets the boolean properties _interface,
_abstract and _sealed to true.
</p>
        <p>
          <strong>Enumerations</strong>
        </p>
        <p>
There are two kinds of enumerations that we can create. One where the enumeration
items act as flags so we may want to combine them and the other type is where we can’t
combine the enumeration items.
</p>
        <p>
The first type is created using the createFlags method and the second one is created
using the createEnum method (of the Type class). The parameters for those methods
are:
</p>
        <p>
Type.createFlags(enumerationName, enumerationItems)<br />
Type.createEnum(enumerationName, enumerationItems)
</p>
        <p>
          <br />
Where enumerationName is the name of the enumeration, and enumerationItems are a variable
number of parameters that specify the different enumeration items. Each item in the
enumeration is specified as two parameters, the first is the string with the item
name, and the second the associated value.
</p>
        <p>
The common methods are:<br />
• toString: converts the value passed to the method to a string.<br />
• parse: converts the string passed to a value.<br />
• getName: returns the name of the enumeration
</p>
        <p>
The enumeration where you can use the items as flags has a method called isFlags that
return true. The other enumeration type has a method called isEnum that returns true,
and a method called getValues that returns a hashtable with the items of the enumeration.
</p>
        <p>
An example follows:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
Type.createEnum(<span style="COLOR: maroon">'Manu.Atlas.Tests.MyEnum'</span>, <span style="COLOR: maroon">'enum_item1'</span>,
1, <span style="COLOR: maroon">'enum_item2'</span>, 2);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> val = Manu.Atlas.Tests.MyEnum.enum_item1;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> str = Manu.Atlas.Tests.MyEnum.toString(val);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> valaux = Manu.Atlas.Tests.MyEnum.parse(<span style="COLOR: maroon">'enum_item2'</span>);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
Type.createFlags(<span style="COLOR: maroon">'Manu.Atlas.Tests.MyEnum2'</span>, <span style="COLOR: maroon">'enum_item1'</span>,
1, <span style="COLOR: maroon">'enum_item2'</span>, 2, <span style="COLOR: maroon">'enum_item3'</span>,
4);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> val2 = Manu.Atlas.Tests.MyEnum2.enum_item1 |
Manu.Atlas.Tests.MyEnum2.enum_item3;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> str2 = Manu.Atlas.Tests.MyEnum2.toString(val2);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> val2aux = Manu.Atlas.Tests.MyEnum2.parse(<span style="COLOR: maroon">'enum_item2
| enum_item3'</span>);
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
The values of the variables after execution are:
</p>
        <p>
val = 1<br />
str = “enum_item1”<br />
valaux = 2<br />
val2 = 5<br />
str2 = “enum_item1 | enum_item3”<br />
val2aux = 6
</p>
        <p>
Both kinds of enumerations are implemented the same way. A hashtable with the same
name as the enumeration is created, and each enumeration item name is stored as a
key of the hashtable and the enumeration item value is stored as the associated value
for the key.
</p>
        <p>
From now on, when showing a class or an interface, I’ll be using C# syntax to show
it instead of the JavaScript version of the class for clarity. The naming convention
for the JavaScript classes is distinct from the C# naming convention so if a property
is called Text in C#, the equivalent getter and setter will be get_text and set_text
instead of get_Text and set_Text, so don’t get confused.
</p>
        <p>
          <strong>Attributes</strong>
        </p>
        <p>
In .NET is very common to decorate classes, properties and methods with attributes
that provide useful information about them. The Microsoft AJAX library adds this extension
to JavaScript.
</p>
        <p>
The attributes are very important to generate reusable code. The xml-script parsing
process and the validation controls use it.
</p>
        <p>
An attribute is a static property of the class Sys.Attributes. The class has a method
called defineAttribute that creates a new attribute:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
Sys.Attributes.defineAttribute(<span style="COLOR: maroon">'MyCustomAttribute'</span>);
</p>
        </div>
        <!--EndFragment-->
        <p>
After having created the attribute we can reference it using Sys.Attributes. 'MyCustomAttribute.
The attributes can be associated to a class or to a property as we will see in the
next section. 
</p>
        <p>
          <strong>Reflection</strong>
        </p>
        <p>
Even if JavaScript has some flexibility that can be used to perform some tasks similar
to what reflection does (retrieve all fields from an object, retrieve a field from
an instance using a string with the property name, invoke a method from an object
based on the method name, etc), as the Microsoft AJAX library added OO features to
it, it has to provide a way to interact with all the new OO infrastructure generically
and more .NET friendly.
</p>
        <p>
These features are provided by the Sys.TypeDescriptor class. Most of the classes in
the library implement the interface ITypeDescriptorProvider:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">interface</span>
            <span style="COLOR: teal">ITypeDescriptorProvider</span>
          </p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: teal">TypeDescriptor</span> GetDescriptor();
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
The only method present in the interface returns the TypeDescriptor for the class
implementing the interface.
</p>
        <p>
The TypeDescriptor class is like this:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">sealed</span>
            <span style="COLOR: blue">class</span>
            <span style="COLOR: teal">TypeDescriptor</span>
          </p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> AddAttribute(<span style="COLOR: blue">string</span> name, <span style="COLOR: blue">object</span> value);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> AddEvent(<span style="COLOR: blue">string</span> name, <span style="COLOR: blue">object</span> supportActions);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> AddMethod(<span style="COLOR: blue">string</span> name, <span style="COLOR: blue">object</span> value);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> AddProperty(<span style="COLOR: blue">string</span> name, <span style="COLOR: teal">Type</span> type, <span style="COLOR: blue">bool</span> readOnly, <span style="COLOR: blue">params</span><span style="COLOR: blue">object</span>[]
attributes);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> TypeDescriptor();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: blue">void</span> AddType(<span style="COLOR: blue">string</span> tagPrefix, <span style="COLOR: blue">string</span> tagName, <span style="COLOR: teal">Type</span> type);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: teal">Type</span> GetPropertyType(<span style="COLOR: blue">object</span> instance, <span style="COLOR: blue">string</span> name, <span style="COLOR: blue">string</span> key);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: teal">Type</span> GetType(<span style="COLOR: blue">string</span> tagPrefix, <span style="COLOR: blue">string</span> tagName);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: teal">TypeDescriptor</span> GetTypeDescriptor(<span style="COLOR: blue">object</span> instance);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: blue">object</span> InvokeMethod(<span style="COLOR: blue">object</span> instance, <span style="COLOR: blue">string</span> name, <span style="COLOR: blue">object</span>[]
parameters);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: teal">ParameterInfo</span> CreateParameter(<span style="COLOR: blue">string</span> name, <span style="COLOR: teal">Type</span> type);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: blue">string</span> GetAttribute(<span style="COLOR: blue">object</span> instance, <span style="COLOR: blue">string</span> name);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: blue">object</span> GetProperty(<span style="COLOR: blue">object</span> instance, <span style="COLOR: blue">string</span> name, <span style="COLOR: blue">string</span> key);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: blue">void</span> SetProperty(<span style="COLOR: blue">object</span> instance, <span style="COLOR: blue">string</span> name, <span style="COLOR: blue">object</span> value, <span style="COLOR: blue">string</span> key);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: blue">void</span> Unload();
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
A class implementing ITypeDescriptorProvider returns a new instance of the TypeDescriptor
class where all the attributes, properties, methods are events supported by the class
have been added using the AddXXX instance methods. The CreateParameter method is used
with the AddMethod method to specify the parameters for the method. 
</p>
        <p>
The information about a particular instance is stored in four dictionaries (_attributes,
_events, _methods and _properties). The static methods AddType and GetType are used
to register types and to get information about the registered types in the system.
The TypeDescriptor class has a static field called _registeredTags (of type hashtable),
where it stores a hashtable of typeNames and its associated type, using the tagPrefix
as key. This is mainly used by the xml-script infrastructure as we’ll see in a future
post. The Unload method erases the information stored in the _registeredTags hashtable.
</p>
        <p>
The other methods are self explanatory.
</p>
        <p>
          <strong>Events</strong>
        </p>
        <p>
The event mechanism implemented by the library is very reminiscent of the .NET one,
although it has some differences.
</p>
        <p>
An event is an instance of the Type.Event class:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">sealed</span>
            <span style="COLOR: blue">class</span>
            <span style="COLOR: teal">Event</span> : <span style="COLOR: teal">IDisposable</span></p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">bool</span> AutoInvoke
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">bool</span> IsInvoked
{ <span style="COLOR: blue">get</span>; }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> Event(<span style="COLOR: teal">Component</span> owner, <span style="COLOR: blue">bool</span> autoInvoke);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> Add(<span style="COLOR: teal">JavascriptFunction</span> handler);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> AddAction(<span style="COLOR: teal">IAction</span> action);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> Remove(<span style="COLOR: teal">JavascriptFunction</span> handler);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> RemoveAction(<span style="COLOR: teal">IAction</span> action);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">bool</span> IsActive();
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> Invoke(<span style="COLOR: blue">object</span> sender, <span style="COLOR: teal">EventArgs</span> eventArgs);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> SetInvoked(<span style="COLOR: blue">bool</span> invoked);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">void</span> Dispose();
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
An event is declared like this:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">this</span>.propertyChanged = <span style="COLOR: blue">new</span> Type.Event(<span style="COLOR: blue">null</span>, <span style="COLOR: blue">false</span>);
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
And to subscribe to the event we have to write the following code:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> propertyChangedHandler = Function.createDelegate(<span style="COLOR: blue">this</span>,
onPropertyChanged);
</p>
          <p style="MARGIN: 0px">
myInstance.propertyChanged.add(propertyChangedHandler);
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
the onPropertyChange method will be called when the event is fired. The method should
have a signature like this:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">function</span> onPropertyChanged(sender, args) {
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
And the first parameter will be the object that fired the event, and the second parameter
will be the arguments specific for the event.
</p>
        <p>
The arguments are an instance of the class EventArgs or any of its subclasses:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">class</span>
            <span style="COLOR: teal">EventArgs</span> : <span style="COLOR: teal">ITypeDescriptorProvider</span></p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: teal">EventArgs</span> Empty
= <span style="COLOR: blue">new</span><span style="COLOR: teal">EventArgs</span>();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span> EventArgs();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">virtual</span><span style="COLOR: teal">TypeDescriptor</span> GetDescriptor();
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
Note that the EventArgs class implements the ITypeDescriptorProvider interface explained
before.
</p>
        <p>
The Event class implements the IDisposable interface that is like this:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">interface</span>
            <span style="COLOR: teal">IDisposable</span>
          </p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">void</span> Dispose();
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
yes, the same as .NET.
</p>
        <p>
The Event class has methods to add and remove event handlers and also to add and remove
actions. What is an action? Actions will be covered in more detail in a future post
but for now think of them as tasks that can be executed before the event handler is
called or after the event handler is called. 
</p>
        <p>
The Event constructor takes a Component as the first parameter, because actions operate
on components. The autoInvoke parameter is used to call to a handler when adding it
to the event if the event has already been fired. This is useful because some critical
methods should be called in response to events that may happen before the full Microsoft
AJAX Library has been initialized.
</p>
        <p>
          <strong>Additions to the default JavaScript objects</strong>
        </p>
        <p>
The library adds some methods to the default JavaScript objects to make them more
.NET alike:
</p>
        <p>
Boolean -&gt; parse<br />
Number -&gt; parse<br />
String -&gt; startsWith, endsWith, lTrim, rTrim, format, localeFormat<br />
Array -&gt; add, addRange, cloar, clone, contains, dequeue, indexOf, foreach, insert,
remove, removeAt, parse, get_length, get_Item. Also, Array implements the IArray interface
(get_length, get_Item).
</p>
        <p>
RegExp -&gt; parse
</p>
        <p>
Error -&gt; createError (that is the replacement for: throw new Exception(…) in the
.net framework.
</p>
        <p>
Date -&gt; toFormattedString, serialize
</p>
        <p>
In the next post I’ll talk about the Component class and related classes. There is
a lot of theory behind it to fully understand all the details involved…<br /></p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=e440e756-b3fa-4ec2-aea7-f2f28dee1a38" />
      </body>
      <title>Microsoft AJAX Library (Atlas) – Javascript OOP enhancements (Part 2)</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,e440e756-b3fa-4ec2-aea7-f2f28dee1a38.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,e440e756-b3fa-4ec2-aea7-f2f28dee1a38.aspx</link>
      <pubDate>Wed, 11 Oct 2006 08:22:24 GMT</pubDate>
      <description>&lt;p&gt;
Note: Bertrand Le Roy has confirmed that the next Microsoft AJAX Library release will
use the prototype based approach instead of the closure approach (really great news!),
and clearly explains the differences:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://weblogs.asp.net/bleroy/archive/2006/10/11/From-closures-to-prototypes_2C00_-part-1.aspx"&gt;http://weblogs.asp.net/bleroy/archive/2006/10/11/From-closures-to-prototypes_2C00_-part-1.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
In &lt;a href="http://www.manuelabadia.com/blog/PermaLink,guid,c59facc0-301e-4e30-898d-428038828dcd.aspx"&gt;part
1&lt;/a&gt; we saw how the inheritance infrastructure worked, how to create namespaces,
and how to create classes. Now it is time to continue with the other stuff.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Interfaces&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
To create an interface is similar to create a class, but we use the registerInterface
method instead and we define the methods to be abstract. For example:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.MyInterface = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.method1 = Function.abstractMethod;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.MyInterface.registerInterface(&lt;span style="COLOR: maroon"&gt;'Manu.Atlas.Tests.MyInterface'&lt;/span&gt;);
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
We can define the interface using the prototype method instead of the closure method:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.MyInterface = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.MyInterface.prototype.method1 = Function.abstractMethod;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.MyInterface.registerInterface(&lt;span style="COLOR: maroon"&gt;'Manu.Atlas.Tests.MyInterface'&lt;/span&gt;);
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The registerInterface method (defined in the Function type) just set the _typeName
of the type where the method is invoked, and sets the boolean properties _interface,
_abstract and _sealed to true.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Enumerations&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
There are two kinds of enumerations that we can create. One where the enumeration
items act as flags so we may want to combine them and the other type is where we can’t
combine the enumeration items.
&lt;/p&gt;
&lt;p&gt;
The first type is created using the createFlags method and the second one is created
using the createEnum method (of the Type class). The parameters for those methods
are:
&lt;/p&gt;
&lt;p&gt;
Type.createFlags(enumerationName, enumerationItems)&lt;br&gt;
Type.createEnum(enumerationName, enumerationItems)
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
Where enumerationName is the name of the enumeration, and enumerationItems are a variable
number of parameters that specify the different enumeration items. Each item in the
enumeration is specified as two parameters, the first is the string with the item
name, and the second the associated value.
&lt;/p&gt;
&lt;p&gt;
The common methods are:&lt;br&gt;
•&amp;nbsp;toString: converts the value passed to the method to a string.&lt;br&gt;
•&amp;nbsp;parse: converts the string passed to a value.&lt;br&gt;
•&amp;nbsp;getName: returns the name of the enumeration
&lt;/p&gt;
&lt;p&gt;
The enumeration where you can use the items as flags has a method called isFlags that
return true. The other enumeration type has a method called isEnum that returns true,
and a method called getValues that returns a hashtable with the items of the enumeration.
&lt;/p&gt;
&lt;p&gt;
An example follows:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
Type.createEnum(&lt;span style="COLOR: maroon"&gt;'Manu.Atlas.Tests.MyEnum'&lt;/span&gt;, &lt;span style="COLOR: maroon"&gt;'enum_item1'&lt;/span&gt;,
1, &lt;span style="COLOR: maroon"&gt;'enum_item2'&lt;/span&gt;, 2);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; val = Manu.Atlas.Tests.MyEnum.enum_item1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; str = Manu.Atlas.Tests.MyEnum.toString(val);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; valaux = Manu.Atlas.Tests.MyEnum.parse(&lt;span style="COLOR: maroon"&gt;'enum_item2'&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Type.createFlags(&lt;span style="COLOR: maroon"&gt;'Manu.Atlas.Tests.MyEnum2'&lt;/span&gt;, &lt;span style="COLOR: maroon"&gt;'enum_item1'&lt;/span&gt;,
1, &lt;span style="COLOR: maroon"&gt;'enum_item2'&lt;/span&gt;, 2, &lt;span style="COLOR: maroon"&gt;'enum_item3'&lt;/span&gt;,
4);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; val2 = Manu.Atlas.Tests.MyEnum2.enum_item1 |
Manu.Atlas.Tests.MyEnum2.enum_item3;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; str2 = Manu.Atlas.Tests.MyEnum2.toString(val2);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; val2aux = Manu.Atlas.Tests.MyEnum2.parse(&lt;span style="COLOR: maroon"&gt;'enum_item2
| enum_item3'&lt;/span&gt;);
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
The values of the variables after execution are:
&lt;/p&gt;
&lt;p&gt;
val = 1&lt;br&gt;
str = “enum_item1”&lt;br&gt;
valaux = 2&lt;br&gt;
val2 = 5&lt;br&gt;
str2 = “enum_item1 | enum_item3”&lt;br&gt;
val2aux = 6
&lt;/p&gt;
&lt;p&gt;
Both kinds of enumerations are implemented the same way. A hashtable with the same
name as the enumeration is created, and each enumeration item name is stored as a
key of the hashtable and the enumeration item value is stored as the associated value
for the key.
&lt;/p&gt;
&lt;p&gt;
From now on, when showing a class or an interface, I’ll be using C# syntax to show
it instead of the JavaScript version of the class for clarity. The naming convention
for the JavaScript classes is distinct from the C# naming convention so if a property
is called Text in C#, the equivalent getter and setter will be get_text and set_text
instead of get_Text and set_Text, so don’t get confused.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Attributes&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In .NET is very common to decorate classes, properties and methods with attributes
that provide useful information about them. The Microsoft AJAX library adds this extension
to JavaScript.
&lt;/p&gt;
&lt;p&gt;
The attributes are very important to generate reusable code. The xml-script parsing
process and the validation controls use it.
&lt;/p&gt;
&lt;p&gt;
An attribute is a static property of the class Sys.Attributes. The class has a method
called defineAttribute that creates a new attribute:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
Sys.Attributes.defineAttribute(&lt;span style="COLOR: maroon"&gt;'MyCustomAttribute'&lt;/span&gt;);
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
After having created the attribute we can reference it using Sys.Attributes. 'MyCustomAttribute.
The attributes can be associated to a class or to a property as we will see in the
next section. 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Reflection&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Even if JavaScript has some flexibility that can be used to perform some tasks similar
to what reflection does (retrieve all fields from an object, retrieve a field from
an instance using a string with the property name, invoke a method from an object
based on the method name, etc), as the Microsoft AJAX library added OO features to
it, it has to provide a way to interact with all the new OO infrastructure generically
and more .NET friendly.
&lt;/p&gt;
&lt;p&gt;
These features are provided by the Sys.TypeDescriptor class. Most of the classes in
the library implement the interface ITypeDescriptorProvider:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;interface&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ITypeDescriptorProvider&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: teal"&gt;TypeDescriptor&lt;/span&gt; GetDescriptor();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
The only method present in the interface returns the TypeDescriptor for the class
implementing the interface.
&lt;/p&gt;
&lt;p&gt;
The TypeDescriptor class is like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;sealed&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: teal"&gt;TypeDescriptor&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; AddAttribute(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; name, &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; value);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; AddEvent(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; name, &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; supportActions);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; AddMethod(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; name, &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; value);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; AddProperty(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; name, &lt;span style="COLOR: teal"&gt;Type&lt;/span&gt; type, &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; readOnly, &lt;span style="COLOR: blue"&gt;params&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt;[]
attributes);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; TypeDescriptor();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; AddType(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; tagPrefix, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; tagName, &lt;span style="COLOR: teal"&gt;Type&lt;/span&gt; type);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: teal"&gt;Type&lt;/span&gt; GetPropertyType(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; instance, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; name, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; key);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: teal"&gt;Type&lt;/span&gt; GetType(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; tagPrefix, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; tagName);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: teal"&gt;TypeDescriptor&lt;/span&gt; GetTypeDescriptor(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; instance);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; InvokeMethod(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; instance, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; name, &lt;span style="COLOR: blue"&gt;object&lt;/span&gt;[]
parameters);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ParameterInfo&lt;/span&gt; CreateParameter(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; name, &lt;span style="COLOR: teal"&gt;Type&lt;/span&gt; type);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; GetAttribute(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; instance, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; name);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; GetProperty(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; instance, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; name, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; key);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; SetProperty(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; instance, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; name, &lt;span style="COLOR: blue"&gt;object&lt;/span&gt; value, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; key);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Unload();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
A class implementing ITypeDescriptorProvider returns a new instance of the TypeDescriptor
class where all the attributes, properties, methods are events supported by the class
have been added using the AddXXX instance methods. The CreateParameter method is used
with the AddMethod method to specify the parameters for the method. 
&lt;/p&gt;
&lt;p&gt;
The information about a particular instance is stored in four dictionaries (_attributes,
_events, _methods and _properties). The static methods AddType and GetType are used
to register types and to get information about the registered types in the system.
The TypeDescriptor class has a static field called _registeredTags (of type hashtable),
where it stores a hashtable of typeNames and its associated type, using the tagPrefix
as key. This is mainly used by the xml-script infrastructure as we’ll see in a future
post. The Unload method erases the information stored in the _registeredTags hashtable.
&lt;/p&gt;
&lt;p&gt;
The other methods are self explanatory.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Events&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The event mechanism implemented by the library is very reminiscent of the .NET one,
although it has some differences.
&lt;/p&gt;
&lt;p&gt;
An event is an instance of the Type.Event class:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;sealed&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: teal"&gt;Event&lt;/span&gt; : &lt;span style="COLOR: teal"&gt;IDisposable&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; AutoInvoke
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; IsInvoked
{ &lt;span style="COLOR: blue"&gt;get&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; Event(&lt;span style="COLOR: teal"&gt;Component&lt;/span&gt; owner, &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; autoInvoke);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Add(&lt;span style="COLOR: teal"&gt;JavascriptFunction&lt;/span&gt; handler);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; AddAction(&lt;span style="COLOR: teal"&gt;IAction&lt;/span&gt; action);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Remove(&lt;span style="COLOR: teal"&gt;JavascriptFunction&lt;/span&gt; handler);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; RemoveAction(&lt;span style="COLOR: teal"&gt;IAction&lt;/span&gt; action);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; IsActive();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Invoke(&lt;span style="COLOR: blue"&gt;object&lt;/span&gt; sender, &lt;span style="COLOR: teal"&gt;EventArgs&lt;/span&gt; eventArgs);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; SetInvoked(&lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; invoked);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Dispose();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
An event is declared like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.propertyChanged = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; Type.Event(&lt;span style="COLOR: blue"&gt;null&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;false&lt;/span&gt;);
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
And to subscribe to the event we have to write the following code:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; propertyChangedHandler = Function.createDelegate(&lt;span style="COLOR: blue"&gt;this&lt;/span&gt;,
onPropertyChanged);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
myInstance.propertyChanged.add(propertyChangedHandler);
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
the onPropertyChange method will be called when the event is fired. The method should
have a signature like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;function&lt;/span&gt; onPropertyChanged(sender, args) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
And the first parameter will be the object that fired the event, and the second parameter
will be the arguments specific for the event.
&lt;/p&gt;
&lt;p&gt;
The arguments are an instance of the class EventArgs or any of its subclasses:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: teal"&gt;EventArgs&lt;/span&gt; : &lt;span style="COLOR: teal"&gt;ITypeDescriptorProvider&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: teal"&gt;EventArgs&lt;/span&gt; Empty
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;EventArgs&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; EventArgs();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;virtual&lt;/span&gt; &lt;span style="COLOR: teal"&gt;TypeDescriptor&lt;/span&gt; GetDescriptor();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
Note that the EventArgs class implements the ITypeDescriptorProvider interface explained
before.
&lt;/p&gt;
&lt;p&gt;
The Event class implements the IDisposable interface that is like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;interface&lt;/span&gt; &lt;span style="COLOR: teal"&gt;IDisposable&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; Dispose();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
yes, the same as .NET.
&lt;/p&gt;
&lt;p&gt;
The Event class has methods to add and remove event handlers and also to add and remove
actions. What is an action? Actions will be covered in more detail in a future post
but for now think of them as tasks that can be executed before the event handler is
called or after the event handler is called. 
&lt;/p&gt;
&lt;p&gt;
The Event constructor takes a Component as the first parameter, because actions operate
on components. The autoInvoke parameter is used to call to a handler when adding it
to the event if the event has already been fired. This is useful because some critical
methods should be called in response to events that may happen before the full Microsoft
AJAX Library has been initialized.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Additions to the default JavaScript objects&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The library adds some methods to the default JavaScript objects to make them more
.NET alike:
&lt;/p&gt;
&lt;p&gt;
Boolean -&amp;gt; parse&lt;br&gt;
Number -&amp;gt; parse&lt;br&gt;
String -&amp;gt; startsWith, endsWith, lTrim, rTrim, format, localeFormat&lt;br&gt;
Array -&amp;gt; add, addRange, cloar, clone, contains, dequeue, indexOf, foreach, insert,
remove, removeAt, parse, get_length, get_Item. Also, Array implements the IArray interface
(get_length, get_Item).
&lt;/p&gt;
&lt;p&gt;
RegExp -&amp;gt; parse
&lt;/p&gt;
&lt;p&gt;
Error -&amp;gt; createError (that is the replacement for: throw new Exception(…) in the
.net framework.
&lt;/p&gt;
&lt;p&gt;
Date -&amp;gt; toFormattedString, serialize
&lt;/p&gt;
&lt;p&gt;
In the next post I’ll talk about the Component class and related classes. There is
a lot of theory behind it to fully understand all the details involved…&lt;br&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=e440e756-b3fa-4ec2-aea7-f2f28dee1a38" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,e440e756-b3fa-4ec2-aea7-f2f28dee1a38.aspx</comments>
      <category>Ajax;ASP.NET;JavaScript</category>
    </item>
    <item>
      <trackback:ping>http://www.manuelabadia.com/blog/Trackback.aspx?guid=c59facc0-301e-4e30-898d-428038828dcd</trackback:ping>
      <pingback:server>http://www.manuelabadia.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.manuelabadia.com/blog/PermaLink,guid,c59facc0-301e-4e30-898d-428038828dcd.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.manuelabadia.com/blog/CommentView,guid,c59facc0-301e-4e30-898d-428038828dcd.aspx</wfw:comment>
      <wfw:commentRss>http://www.manuelabadia.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=c59facc0-301e-4e30-898d-428038828dcd</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have started to look at Atlas. The first thing I have played with is the layer to
provide better OOP features for Javascript.
</p>
        <p>
Note: this is based on an early version of the product (July CTP), so this information
can change for the final release.
</p>
        <p>
          <strong>Javascript OOP features</strong>
        </p>
        <p>
Javascript is a prototype-based object oriented language. This means that every object
has a prototype, an object from which it inherits properties and methods. The prototype
is a shared property of the class that can be accessed like this:
</p>
        <p>
myClass.prototype
</p>
        <p>
As Javascript is an interpreted language, when the interpreter founds an expression
like:
</p>
        <p>
myObject.myProperty
</p>
        <p>
first it checks if the object instance “myObject” has a property called “myProperty”.
If not, then it tries to find that property in the prototype object of that class
(myClass.prototype.myProperty). This prototype relationship is recursive, because
the prototype is an object that can have a prototype, so this recursion ends only
when Object is reached, the superclass of all objects.
</p>
        <p>
In Javascript, a class is defined by a function (the constructor) and its prototype
(that defines the properties and methods that each object instance has by default,
because of how the interpreter evaluates the expressions).
</p>
        <p>
So, to define a class in Javascript we have to do this:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
TestClass = <span style="COLOR: blue">function</span>() {
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
If we want to add a method to the class we can do it like this:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
TestClass = <span style="COLOR: blue">function</span>() {
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>.method1 = <span style="COLOR: blue">function</span>(){
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
Or like this:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
TestClass = <span style="COLOR: blue">function</span>() {
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
TestClass.prototype.method2 = <span style="COLOR: blue">function</span>(){
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
What's the difference? Consider the following class:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
TestClass = <span style="COLOR: blue">function</span>() {
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>.method1 = <span style="COLOR: blue">function</span>(){
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
TestClass.prototype.method2 = <span style="COLOR: blue">function</span>(){
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
          <!--EndFragment-->
        </p>
        <p>
If we instantiate two objects of the class TestClass, we can see the difference:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> objTestClass1 = <span style="COLOR: blue">new</span> TestClass();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> objTestClass2 = <span style="COLOR: blue">new</span> TestClass();
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
This diagram shows the internal representation of the object:
</p>
        <p>
          <img src="http://www.manuelabadia.com/blog/content/binary/javascriptOO.png" border="0" />
        </p>
        <p>
          <br />
As you can see, the method declared using the prototype is shared between instances
of the class. However, the method added in the constructor is created for each instance.
So:
</p>
        <p>
objTestClass1.method1 != objTestClass2.method1 
<br />
and 
<br />
objTestClass1.method2 == objTestClass2.method2
</p>
        <p>
Basically, the prototype is the only “object oriented mechanism” present in Javascript.
As you can see it is not an usual object oriented language. Using the prototype
you can come up with your own solution to simulate a more complete object oriented
language (inheritance, virtual methods, calling the base method, etc).
</p>
        <p>
          <strong>Atlas OOP features</strong>
        </p>
        <p>
Atlas adds some valuable features to provide a more natural object oriented programming
models. What Atlas offers is:<br />
• namespaces<br />
• inheritance<br />
• properties<br />
• defining virtual methods<br />
• calling base methods<br />
• interfaces<br />
• enumerations<br />
• attributes<br />
• reflection
</p>
        <p>
          <strong>Namespaces</strong>
        </p>
        <p>
To create a namespace in Atlas you have to write something like:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
Type.registerNamespace(<span style="COLOR: maroon">'Manu.Atlas.Tests'</span>);
</p>
        </div>
        <!--EndFragment-->
        <p>
          <br />
Internally Atlas adds a Type property to the window object (the default Javascript
context), and assigns it the Function built-in type. Atlas adds a lot of methods and
properties to Function, as we’ll see later.
</p>
        <p>
The registerNamespace function splits the namespace by the dots and creates a hierarchy
of objects in the window object that resemble the namespace. For example, for the
namespace Manu.Atlas.Tests the following properties are created:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
window.Manu = <span style="COLOR: blue">new</span> Object();
</p>
          <p style="MARGIN: 0px">
window.Manu.Atlas = <span style="COLOR: blue">new</span> Object();
</p>
          <p style="MARGIN: 0px">
window.Manu.Atlas.Tests = <span style="COLOR: blue">new</span> Object();
</p>
        </div>
        <p>
          <!--EndFragment-->
          <br />
          <strong>Inheritance</strong>
        </p>
        <p>
Atlas theorically supports multiple inheritance, but in the July release it isn’t
working properly. Anyway, multiple inheritance support will be removed before the
final version, so don't count on it.
</p>
        <p>
A class in Atlas has to be registered to work properly. The syntax to register a class
is:
</p>
        <p>
FullClassName.registerClass(typeName, baseTypes, interfaces)
</p>
        <p>
Only the first parameter is mandatory. The second parameter specifies the base class
or base classes if multiple inheritance is used. The second parameter could be a reference
to the base class or an array of type names for the base class (or classes). The third
parameter is the interface implemented by the class (if any). A class can implement
multiple interfaces so you can call registerClass with more than 3 parameters. Any
extra parameter should be an interface that is being implemented by the class.
</p>
        <p>
Atlas adds some information to each class type it creates to provide the necessary
machinery for the object oriented features:
</p>
        <p>
• _typeName field: with the name of the type (the function getTypeName returns
it).<br />
• _baseType field: a reference to the parent type (the function getBaseType returns.<br />
• _basePrototypePending property: a boolean that is used to know if the class
has been initialized (more on this later).<br />
• _interfaces: an array with references to the interfaces implemented by the
class.<br />
• bases: an array with references to the parent classes.<br />
• _interface, _sealed and _abstract boolean properties to give information about
the type.<br />
• _baseMethods: a hash table where methods that can be called by child classes
are stored.
</p>
        <p>
The core of the inheritance mechanism is handled by the initializeBase function that
has to be called in the constructor of a derived class. The syntax is:
</p>
        <p>
FullClassName.initializeBase(instance, baseArguments)
</p>
        <p>
Where the first parameter is the instance to be initialized and the second parameter
is an array of arguments to pass to the base constructor.
</p>
        <p>
The initializeBase method starts calling the constructor for each interface in the
class (stored in the _interfaces collection). Then calls the _setBases method and
finally calls the _callBaseConstructors method.
</p>
        <p>
The _setBases method does an important job. If the class inherits from another class,
the method iterates through all the base classes, filling the bases collection, and
recursively calling the _setBases method on the base classes. After the _setBases
method has been called for a base class, the _copyProps method is called. The _copyProps
method iterates through all properties and methods stored in the prototype of the
base class and stores them in them in the prototype of the subclass. So, after the
call to _copyProps, the subclass also has the properties and methods specified in
the prototype of the base class.
</p>
        <p>
The _callBaseConstructors method iterates through the bases array, calling the base
constructor with the current object instance.
</p>
        <p>
So, after calling the initializeBase method, the object has all the properties and
methods of the base classes, giving the illusion of inheritance.
</p>
        <p>
If we declare the methods and properties in the prototype, they will be created in
the child classes in the _copyProps method. If we create the properties and methods
in the constructor, they will be created in the child classes in the _callBaseConstructors
method.
</p>
        <p>
An example of a class B that inherits from A is:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
Type.registerNamespace(<span style="COLOR: maroon">'Manu.Atlas.Tests'</span>);
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.A = <span style="COLOR: blue">function</span> (a1, a2) {
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>._a1 = a1;
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>._a2 = a2;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.A.prototype._a1 = 0;
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.A.prototype._a2 = 0;
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.A.prototype.get_a1 = <span style="COLOR: blue">function</span> ()
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">return</span><span style="COLOR: blue">this</span>._a1;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.A.prototype.set_a1 = <span style="COLOR: blue">function</span>(value)
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>._a1 = value;
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">return</span> value;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.A.prototype.get_a2 = <span style="COLOR: blue">function</span> ()
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">return</span><span style="COLOR: blue">this</span>._a2;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.A.prototype.set_a2 = <span style="COLOR: blue">function</span>(value)
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>._a2 = value;
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">return</span> value;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.B = <span style="COLOR: blue">function</span> (a1, a2, b1) {
</p>
          <p style="MARGIN: 0px">
    Manu.Atlas.Tests.B.initializeBase(<span style="COLOR: blue">this</span>,
[ a1, a2 ]);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>._b1 = b1;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.B.prototype._b1 = 0;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.B.prototype.get_b1 = <span style="COLOR: blue">function</span> ()
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">return</span><span style="COLOR: blue">this</span>._b1;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.B.prototype.set_b1 = <span style="COLOR: blue">function</span>(value)
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>._b1 = value;
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">return</span> value;
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.A.registerClass(<span style="COLOR: maroon">'Manu.Atlas.Tests.A'</span>, <span style="COLOR: blue">null</span>);
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.B.registerClass(<span style="COLOR: maroon">'Manu.Atlas.Tests.B'</span>,
Manu.Atlas.Tests.A);
</p>
        </div>
        <!--EndFragment-->
        <p>
          <br />
Note that we have created the properties and methods using the prototype in order
to save memory. We can declare the A class like this:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.A = <span style="COLOR: blue">function</span> (a1, a2) {
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>._a1 = a1;
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>._a2 = a2;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>.get_a1 = <span style="COLOR: blue">function</span> ()
{
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">return</span><span style="COLOR: blue">this</span>._a1;
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>.set_a1 = <span style="COLOR: blue">function</span> (value)
{
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">this</span>._a1 =
value;
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>.get_a2 = <span style="COLOR: blue">function</span> ()
{
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">return</span><span style="COLOR: blue">this</span>._a2;
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">this</span>.set_a2 = <span style="COLOR: blue">function</span> (value)
{
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">this</span>._a2 =
value;
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <!--EndFragment-->
        <p>
          <br />
And it will be functionally equivalent although it will be more expensive in memory
terms as each object instance will have 4 methods instead of sharing them (as
explained before). This mode of creating a class is called the closure model. The
previous one is called the prototype mode.
</p>
        <p>
If we create an object of type B, we can call the base properties. In the following
sample, the last line evaluates to 3:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> objA = <span style="COLOR: blue">new</span> Manu.Atlas.Tests.A(2,
7);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> objB = <span style="COLOR: blue">new</span> Manu.Atlas.Tests.B(1,
3, 5);
</p>
          <p style="MARGIN: 0px">
objB.get_a2();
</p>
        </div>
        <p>
          <!--EndFragment-->
          <br />
          <br />
There are more functions to register a class, depending on the behaviour of the class:<br />
registerSealedClass and registerAbstractClass. The name clearly shows when to use
them although they just set a property and call to the registerClass method. If a
class is registered using registerSealedClass any class inheriting from it will not
have its members copied because the _setBases method will not be called although no
error will appear.
</p>
        <p>
The Function built in type is also extended with some methods to check interface implementation,
inheritance and type:<br />
• implementsInterface<br />
• isImplementedBy<br />
• inheritsFrom<br />
• isInstanceOfType
</p>
        <p>
          <strong>Properties</strong>
        </p>
        <p>
As javascript doesn't have properties like C#, the recommended approach (and what
is used in the atlas library) is to provide a getter and a setter method for properties
with the signature get_propertyName set_propertyName as we did earlier for the Manu.Atlas.Tests.A
class. It is really important that the getter starts with "get_" and the setter with
"set_" as this is mandatory for integrating our custom components into the Atlas framework
as we will see in a future. 
</p>
        <p>
          <strong>Methods</strong>
        </p>
        <p>
The initializeBase method provided most of the machinery for the OOP with Atlas, but
there is something missing: how to call a base method from an overridden method.
</p>
        <p>
Atlas provides 3 methods related to this problem:<br />
• registerBaseMethod<br />
• callBaseMethod<br />
• getBaseMethod
</p>
        <p>
The first one is saves a method in the _baseMethods hash table, in order for a child
class to call to the base class implementation. The child class has to call to the
callBaseMethod for this, and the implementation of callBaseMethod uses the getBaseMethod
method in order to obtain a reference to the base method.
</p>
        <p>
There is no need to call to the registerBaseMethod if we define our methods using
the prototype because the getBaseMethod searchs the method in the prototype if it
isn’t found in the _baseMethods hash table. 
</p>
        <p>
An example of a class with a method that calls the base method follows:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.C = <span style="COLOR: blue">function</span> (a1, a2, b1) {
</p>
          <p style="MARGIN: 0px">
    Manu.Atlas.Tests.C.initializeBase(<span style="COLOR: blue">this</span>,
[ a1, a2, b1 ]);
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.C.prototype.get_b1 = <span style="COLOR: blue">function</span> ()
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">return</span> Manu.Atlas.Tests.C.callBaseMethod(<span style="COLOR: blue">this</span>, <span style="COLOR: maroon">'get_b1'</span>);
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.C.prototype.set_b1 = <span style="COLOR: blue">function</span> (value)
{
</p>
          <p style="MARGIN: 0px">
    Manu.Atlas.Tests.C.callBaseMethod(<span style="COLOR: blue">this</span>, <span style="COLOR: maroon">'set_b1'</span>,
[ value ]);
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
Manu.Atlas.Tests.C.registerClass(<span style="COLOR: maroon">'Manu.Atlas.Tests.C'</span>,
Manu.Atlas.Tests.B);
</p>
        </div>
        <!--EndFragment-->
        <p>
 
</p>
        <p>
The Function built in type is extended with two static functions to help when creating
a class or an interface:<br />
• abstractMethod: method that throws an exception if called.<br />
• emptyFunction: the name says it all.
</p>
        <p>
I’m running out of time now so in another post I’ll finish talking about the OO features
of Atlas.
</p>
        <img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=c59facc0-301e-4e30-898d-428038828dcd" />
      </body>
      <title>Microsoft AJAX Library (Atlas) – Javascript OOP enhancements (Part 1)</title>
      <guid isPermaLink="false">http://www.manuelabadia.com/blog/PermaLink,guid,c59facc0-301e-4e30-898d-428038828dcd.aspx</guid>
      <link>http://www.manuelabadia.com/blog/PermaLink,guid,c59facc0-301e-4e30-898d-428038828dcd.aspx</link>
      <pubDate>Tue, 26 Sep 2006 22:34:38 GMT</pubDate>
      <description>&lt;p&gt;
I have started to look at Atlas. The first thing I have played with is the layer to
provide better OOP features for Javascript.
&lt;/p&gt;
&lt;p&gt;
Note: this is based on an early version of the product (July CTP), so this information
can change for the final release.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Javascript OOP features&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Javascript is a prototype-based object oriented language. This means that every object
has a prototype, an object from which it inherits properties and methods. The prototype
is a shared property of the class that can be accessed like this:
&lt;/p&gt;
&lt;p&gt;
myClass.prototype
&lt;/p&gt;
&lt;p&gt;
As Javascript is an interpreted language, when the interpreter founds an expression
like:
&lt;/p&gt;
&lt;p&gt;
myObject.myProperty
&lt;/p&gt;
&lt;p&gt;
first it checks if the object instance “myObject” has a property called “myProperty”.
If not, then it tries to find that property in the prototype object of that class
(myClass.prototype.myProperty). This prototype relationship is recursive, because
the prototype is an object that can have a prototype, so this recursion ends only
when Object is reached, the superclass of all objects.
&lt;/p&gt;
&lt;p&gt;
In Javascript, a class is defined by a function (the constructor) and its prototype
(that defines the properties and methods that each object instance has by default,
because of how the interpreter evaluates the expressions).
&lt;/p&gt;
&lt;p&gt;
So, to define a class in Javascript we have to do this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
TestClass = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
If we want to add a method to the class we can do it like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
TestClass = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.method1 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;(){
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
Or like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
TestClass = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
TestClass.prototype.method2 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;(){
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
What's the difference? Consider the following class:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
TestClass = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;() {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.method1 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;(){
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
TestClass.prototype.method2 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;(){
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;p&gt;
If we instantiate two objects of the class TestClass, we can see the difference:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; objTestClass1 = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; TestClass();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; objTestClass2 = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; TestClass();
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
This diagram shows the internal representation of the object:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.manuelabadia.com/blog/content/binary/javascriptOO.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
As you can see, the method declared using the prototype is shared between instances
of the class. However, the method added in the constructor is created for each instance.
So:
&lt;/p&gt;
&lt;p&gt;
objTestClass1.method1 != objTestClass2.method1 
&lt;br&gt;
and 
&lt;br&gt;
objTestClass1.method2 == objTestClass2.method2
&lt;/p&gt;
&lt;p&gt;
Basically, the prototype is the only “object oriented mechanism” present in Javascript.
As you can see it is not an usual object oriented&amp;nbsp;language. Using the prototype
you can come up with your own solution to simulate a more complete object oriented
language (inheritance, virtual methods, calling the base method, etc).
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Atlas OOP features&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Atlas adds some valuable features to provide a more natural object oriented programming
models. What Atlas offers is:&lt;br&gt;
•&amp;nbsp;namespaces&lt;br&gt;
•&amp;nbsp;inheritance&lt;br&gt;
•&amp;nbsp;properties&lt;br&gt;
•&amp;nbsp;defining virtual methods&lt;br&gt;
•&amp;nbsp;calling base methods&lt;br&gt;
•&amp;nbsp;interfaces&lt;br&gt;
•&amp;nbsp;enumerations&lt;br&gt;
•&amp;nbsp;attributes&lt;br&gt;
•&amp;nbsp;reflection
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Namespaces&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
To create a namespace in Atlas you have to write something like:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
Type.registerNamespace(&lt;span style="COLOR: maroon"&gt;'Manu.Atlas.Tests'&lt;/span&gt;);
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&lt;br&gt;
Internally Atlas adds a Type property to the window object (the default Javascript
context), and assigns it the Function built-in type. Atlas adds a lot of methods and
properties to Function, as we’ll see later.
&lt;/p&gt;
&lt;p&gt;
The registerNamespace function splits the namespace by the dots and creates a hierarchy
of objects in the window object that resemble the namespace. For example, for the
namespace Manu.Atlas.Tests the following properties are created:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
window.Manu = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; Object();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
window.Manu.Atlas = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; Object();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
window.Manu.Atlas.Tests = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; Object();
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;br&gt;
&lt;strong&gt;Inheritance&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Atlas theorically supports multiple inheritance, but in the July release it isn’t
working properly. Anyway, multiple inheritance support will be removed before the
final version, so don't count on it.
&lt;/p&gt;
&lt;p&gt;
A class in Atlas has to be registered to work properly. The syntax to register a class
is:
&lt;/p&gt;
&lt;p&gt;
FullClassName.registerClass(typeName, baseTypes, interfaces)
&lt;/p&gt;
&lt;p&gt;
Only the first parameter is mandatory. The second parameter specifies the base class
or base classes if multiple inheritance is used. The second parameter could be a reference
to the base class or an array of type names for the base class (or classes). The third
parameter is the interface implemented by the class (if any). A class can implement
multiple interfaces so you can call registerClass with more than 3 parameters. Any
extra parameter should be an interface that is being implemented by the class.
&lt;/p&gt;
&lt;p&gt;
Atlas adds some information to each class type it creates to provide the necessary
machinery for the object oriented features:
&lt;/p&gt;
&lt;p&gt;
•&amp;nbsp;_typeName field: with the name of the type (the function getTypeName returns
it).&lt;br&gt;
•&amp;nbsp;_baseType field: a reference to the parent type (the function getBaseType returns.&lt;br&gt;
•&amp;nbsp;_basePrototypePending property: a boolean that is used to know if the class
has been initialized (more on this later).&lt;br&gt;
•&amp;nbsp;_interfaces: an array with references to the interfaces implemented by the
class.&lt;br&gt;
•&amp;nbsp;bases: an array with references to the parent classes.&lt;br&gt;
•&amp;nbsp;_interface, _sealed and _abstract boolean properties to give information about
the type.&lt;br&gt;
•&amp;nbsp;_baseMethods: a hash table where methods that can be called by child classes
are stored.
&lt;/p&gt;
&lt;p&gt;
The core of the inheritance mechanism is handled by the initializeBase function that
has to be called in the constructor of a derived class. The syntax is:
&lt;/p&gt;
&lt;p&gt;
FullClassName.initializeBase(instance, baseArguments)
&lt;/p&gt;
&lt;p&gt;
Where the first parameter is the instance to be initialized and the second parameter
is an array of arguments to pass to the base constructor.
&lt;/p&gt;
&lt;p&gt;
The initializeBase method starts calling the constructor for each interface in the
class (stored in the _interfaces collection). Then calls the _setBases method and
finally calls the _callBaseConstructors method.
&lt;/p&gt;
&lt;p&gt;
The _setBases method does an important job. If the class inherits from another class,
the method iterates through all the base classes, filling the bases collection, and
recursively calling the _setBases method on the base classes. After the _setBases
method has been called for a base class, the _copyProps method is called. The _copyProps
method iterates through all properties and methods stored in the prototype of the
base class and stores them in them in the prototype of the subclass. So, after the
call to _copyProps, the subclass also has the properties and methods specified in
the prototype of the base class.
&lt;/p&gt;
&lt;p&gt;
The _callBaseConstructors method iterates through the bases array, calling the base
constructor with the current object instance.
&lt;/p&gt;
&lt;p&gt;
So, after calling the initializeBase method, the object has all the properties and
methods of the base classes, giving the illusion of inheritance.
&lt;/p&gt;
&lt;p&gt;
If we declare the methods and properties in the prototype, they will be created in
the child classes in the _copyProps method. If we create the properties and methods
in the constructor, they will be created in the child classes in the _callBaseConstructors
method.
&lt;/p&gt;
&lt;p&gt;
An example of a class B that inherits from A is:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
Type.registerNamespace(&lt;span style="COLOR: maroon"&gt;'Manu.Atlas.Tests'&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.A = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt; (a1, a2) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._a1 = a1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._a2 = a2;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.A.prototype._a1 = 0;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.A.prototype._a2 = 0;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.A.prototype.get_a1 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt; ()
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._a1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.A.prototype.set_a1 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;(value)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._a1 = value;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; value;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.A.prototype.get_a2 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt; ()
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._a2;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.A.prototype.set_a2 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;(value)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._a2 = value;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; value;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.B = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt; (a1, a2, b1) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Manu.Atlas.Tests.B.initializeBase(&lt;span style="COLOR: blue"&gt;this&lt;/span&gt;,
[ a1, a2 ]);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._b1 = b1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.B.prototype._b1 = 0;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.B.prototype.get_b1 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt; ()
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._b1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.B.prototype.set_b1 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt;(value)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._b1 = value;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; value;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.A.registerClass(&lt;span style="COLOR: maroon"&gt;'Manu.Atlas.Tests.A'&lt;/span&gt;, &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.B.registerClass(&lt;span style="COLOR: maroon"&gt;'Manu.Atlas.Tests.B'&lt;/span&gt;,
Manu.Atlas.Tests.A);
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&lt;br&gt;
Note that we have created the properties and methods using the prototype in order
to save memory. We can declare the A class like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.A = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt; (a1, a2) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._a1 = a1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._a2 = a2;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.get_a1 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt; ()
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._a1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.set_a1 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt; (value)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._a1 =
value;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.get_a2 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt; ()
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._a2;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.set_a2 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt; (value)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;._a2 =
value;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&lt;br&gt;
And it will be functionally equivalent although it will be more expensive in memory
terms as each object instance will have&amp;nbsp;4 methods instead of sharing them (as
explained before). This mode of creating a class is called the closure model. The
previous one is called the prototype mode.
&lt;/p&gt;
&lt;p&gt;
If we create an object of type B, we can call the base properties. In the following
sample, the last line evaluates to 3:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; objA = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; Manu.Atlas.Tests.A(2,
7);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; objB = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; Manu.Atlas.Tests.B(1,
3, 5);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
objB.get_a2();
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;!--EndFragment--&gt;
&lt;br&gt;
&lt;br&gt;
There are more functions to register a class, depending on the behaviour of the class:&lt;br&gt;
registerSealedClass and registerAbstractClass. The name clearly shows when to use
them although they just set a property and call to the registerClass method. If a
class is registered using registerSealedClass any class inheriting from it will not
have its members copied because the _setBases method will not be called although no
error will appear.
&lt;/p&gt;
&lt;p&gt;
The Function built in type is also extended with some methods to check interface implementation,
inheritance and type:&lt;br&gt;
•&amp;nbsp;implementsInterface&lt;br&gt;
•&amp;nbsp;isImplementedBy&lt;br&gt;
•&amp;nbsp;inheritsFrom&lt;br&gt;
•&amp;nbsp;isInstanceOfType
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Properties&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
As javascript doesn't have properties like C#, the recommended approach (and what
is used in the atlas library) is to provide a getter and a setter method for properties
with the signature get_propertyName set_propertyName as we did earlier for the Manu.Atlas.Tests.A
class. It is really important that the getter starts with "get_" and the setter with
"set_" as this is mandatory for integrating our custom components into the Atlas framework
as we will see in a future. 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Methods&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The initializeBase method provided most of the machinery for the OOP with Atlas, but
there is something missing: how to call a base method from an overridden method.
&lt;/p&gt;
&lt;p&gt;
Atlas provides 3 methods related to this problem:&lt;br&gt;
•&amp;nbsp;registerBaseMethod&lt;br&gt;
•&amp;nbsp;callBaseMethod&lt;br&gt;
•&amp;nbsp;getBaseMethod
&lt;/p&gt;
&lt;p&gt;
The first one is saves a method in the _baseMethods hash table, in order for a child
class to call to the base class implementation. The child class has to call to the
callBaseMethod for this, and the implementation of callBaseMethod uses the getBaseMethod
method in order to obtain a reference to the base method.
&lt;/p&gt;
&lt;p&gt;
There is no need to call to the registerBaseMethod if we define our methods using
the prototype because the getBaseMethod searchs the method in the prototype if it
isn’t found in the _baseMethods hash table. 
&lt;/p&gt;
&lt;p&gt;
An example of a class with a method that calls the base method follows:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.C = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt; (a1, a2, b1) {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Manu.Atlas.Tests.C.initializeBase(&lt;span style="COLOR: blue"&gt;this&lt;/span&gt;,
[ a1, a2, b1 ]);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.C.prototype.get_b1 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt; ()
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; Manu.Atlas.Tests.C.callBaseMethod(&lt;span style="COLOR: blue"&gt;this&lt;/span&gt;, &lt;span style="COLOR: maroon"&gt;'get_b1'&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.C.prototype.set_b1 = &lt;span style="COLOR: blue"&gt;function&lt;/span&gt; (value)
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Manu.Atlas.Tests.C.callBaseMethod(&lt;span style="COLOR: blue"&gt;this&lt;/span&gt;, &lt;span style="COLOR: maroon"&gt;'set_b1'&lt;/span&gt;,
[ value ]);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Manu.Atlas.Tests.C.registerClass(&lt;span style="COLOR: maroon"&gt;'Manu.Atlas.Tests.C'&lt;/span&gt;,
Manu.Atlas.Tests.B);
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The Function built in type is extended with two static functions to help when creating
a class or an interface:&lt;br&gt;
•&amp;nbsp;abstractMethod: method that throws an exception if called.&lt;br&gt;
•&amp;nbsp;emptyFunction: the name says it all.
&lt;/p&gt;
&lt;p&gt;
I’m running out of time now so in another post I’ll finish talking about the OO features
of Atlas.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.manuelabadia.com/blog/aggbug.ashx?id=c59facc0-301e-4e30-898d-428038828dcd" /&gt;</description>
      <comments>http://www.manuelabadia.com/blog/CommentView,guid,c59facc0-301e-4e30-898d-428038828dcd.aspx</comments>
      <category>Ajax;ASP.NET;JavaScript</category>
    </item>
  </channel>
</rss>