Calling a Web Service in Atlas

Posted Wednesday, October 5, 2005 9:20 AM by C-Dog's .NET Tip of the Day
So you have heard about this new atlas crap and you are wondering how it all works.  It turns out in Atlas, there are a lot of different ways to do the same thing.  What I am going to talk about today, is how you can call a web service.  Atlas uses something called json (JavaScript Object Notation) to describe how objects are passed via web services, etc.  To use a web service with Atlas, a different handler is used to generate the proxy toe be used by the javascript.  So in all the examples, you will see this in the web.config.
    <remove verb="*" path="*.asmx"/>
    <add verb="*" path="*.asmx"  type="Microsoft.Web.Services.ScriptHandlerFactory" validate="false"/>
This allows the json representation for that web service method to be returned and included by a script line like this.
<script type="text/javascript" language="JavaScript" src="SimpleService.asmx/js">
When you view the contents of the script, you will get something like the following.
Type.registerNamespace('Quickstart.Samples'); Quickstart.Samples.SimpleService = 
{ path: "/quickstart/atlas/samples/services/SimpleService.asmx", 
EchoString:function(s,onMethodComplete, onMethodTimeout) 
{return Web.Net.ServiceMethodRequest.callMethod(this.path, 
"EchoString",{s:s}, onMethodComplete, onMethodTimeout); } } 
This basically makes calls into the Atlas core javascript libaries which know how to call a web service asynchronously.  The atlas core libraries are included by these lines.
<atlas:Script ID="Script1" runat="server" Path="~/ScriptLibrary/AtlasCompat.js" 
Browser="Mozilla" />
<atlas:Script ID="Script2" runat="server" Path="~/ScriptLibrary/AtlasCompat.js" Browser="Firefox" />
<atlas:Script ID="Script3" runat="server" Path="~/ScriptLibrary/AtlasRuntime.js"/>
Once you have all of that you can just write a javascript method that calls the web service, passing it the input values, an event to call on completion and timeout.
requestSimpleService = Quickstart.Samples.SimpleService.EchoString(
    "SomeText",     //params
    OnComplete,     //Complete event
    OnTimeout       //Timeout event
That really is all that is to it.  If you want to see a working example, try the link below.
If you have not installed the templates yet for it, be sure and do so at the link below.

Read the complete post at