Alright, you saw in the last blog entry how to get the Atlas client framework to download script that wraps a webservice reference: <atlas:ScriptManager ID="scriptManager" runat="server" EnableScriptComponents="true" > <Services> <atlas:ServiceReference Path="SimpleService.asmx" /> </Services> </atlas:ScriptManager>The question now is how does everything tie together? We have reference to a web service here, but that's about it. Bare in mind that the <atlas:ScriptManager> tag is processed server-side instead of client-side, so the ASP.Net runtime is responsible for processing it and not the clientside Atlas framework. What the clientside Atlas framework gets looks like this:
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005"> <references> <add src="SimpleService.asmx/js" /> </references> <components /></page>
...this is what the Atlas framework sees. Now, in a later blog post I'll go into the details of how the client framework parses and builds the script out of the XML script block in general, but for now I'll lightly touch on the topic enough to answer how the JavaScript gets downloaded to the client.
There is a class called Sys.MarkupParser whose responsibility is to deal with markup and, well, parse it. It has a method called _processXMLScript whose responsibility it is to, well, processXMLScript. The method is relatively simple (suprisingly) and looks like this:
this._processXMLScript = function(markupContext, references, componentNodes, completionHandler) { var xmlScriptContext = { markupContext: markupContext, references: references, componentNodes: componentNodes, completionHandler: completionHandler }; if (references && references.length) { var scriptLoader = new Sys.ScriptLoader(); scriptLoader.load(references, Function.createDelegate(this, this._processXMLScriptComponents), xmlScriptContext); } else { this._processXMLScriptComponents(xmlScriptContext); }}
...the section to take note of is, obviously, the one that instantiates the class Sys.ScriptLoader(). It takes all references parsed out of the references block above and snags them. The most pertinent chunk of code from the .load() method above looks like this:
if (_references.length) { var reference = _references.dequeue(); var scriptElement = document.createElement('script'); _currentLoadingReference = scriptElement; if (Sys.Runtime.get_hostType() != Sys.HostType.InternetExplorer) { scriptElement.readyState = 'loaded'; scriptElement.onload = loadReferences; } else { scriptElement.onreadystatechange = loadReferences; } scriptElement.type = 'text/javascript'; scriptElement.src = reference; var headElement = document.getElementsByTagName('head')[0]; headElement.appendChild(scriptElement); return;}
See that the scriptElement.src is set to the 'reference' object, which is a string in this case that points to the web service URI with the "/js" appended. What this means is that the browser references this script as a "src" and therefore is responsible for downloading and loading the script into the script runtime, not the Atlas framework itself. When this URI is hit, the Atlas runtime on the server generates the script and everything links up appropriately.
Happy coding.
Remember Me
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.