This will be a multi-part blog post 'cause the topic is rather extensive. This first part will describe the basics of calling web services via Atlas from the pure programmatic standpoint, plus a bit about how web proxies work in JavaScript. The other entries will go deeper.
First off, visit this Url: http://atlas.asp.net/docs/atlas/samples/services/SimpleService.asmx. What you see here is the nicey user interface wrapping this: http://atlas.asp.net/docs/atlas/samples/services/SimpleService.asmx?WSDL, the service description. If you're a web developer dealing with services, you've seen this before. No big deal.
If you append "/js" to the end of the first querystring, you see something new: http://atlas.asp.net/docs/atlas/samples/services/SimpleService.asmx/js. This is javascript; more interestingly, JavaScript wrapping the methods of the web service itself. After nicely beautifying the script, it looks like this:
Type.registerNamespace('Quickstart.Samples');Quickstart.Samples.SimpleService=new function(){ this.path = "http://atlas.asp.net/docs/atlas/samples/services/SimpleService.asmx"; this.appPath = "http://atlas.asp.net/docs/"; var cm=Sys.Net.ServiceMethod.createProxyMethod; cm(this,"EchoString","s");}
Don't worry too much about the internals of the script above as I'll go into this later (in another post). But, what you've just seen here is that the Atlas framework is capable of dynamically generating javascript to wrap the methods of the web service (the web service this code wraps has one method, EchoString, with one parameter "s"). Interacting with this downloaded code, then, is as easy as doing this:
function OnbuttonGo_click(){ //Call script proxy passing the input element data requestSimpleService = Quickstart.Samples.SimpleService.EchoString( document.getElementById('inputName').value, //params OnComplete, //Complete event OnTimeout //Timeout event ); return false;}
Notice the highlighted method call syntax above. It's really just that easy.
The next question is how does the Atlas client runtime know what services to retrieve proxies for; and the answer lies within the ScriptManager control:
<atlas:ScriptManager ID="scriptManager" runat="server" EnableScriptComponents="true" > <Services> <atlas:ServiceReference Path="SimpleService.asmx" /> </Services> </atlas:ScriptManager>
Remember Me
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.