You are not Logged in
Would you like to Login or Register

Today is: Wednesday, 03 December, 2008
Check this months hot topics

Web service calls from javascript using ATLAS (part 2) - Complex return types

Following on from part one which showed how to make web service calls from javscript, this article will now show the flexibility of the ATLAS framework by calling a web service that returns an object from javascript.

Lets expand from the previous example with the web service below...

public class myReturnClass
{
    public myReturnClass(){
    }

    private string _myProperty1;

    public string myProperty1
    {
        get { return _myProperty1;}
        set { _myProperty1 = value;}
    }

    private string _myProperty2;

    public string myProperty2
    {
        get { return _myProperty2;}
        set { _myProperty2 = value;}
    }
}

public class myWebService : System.Web.Services.WebService
{
    public myWebService () {
    }

    [WebMethod]
    public myReturnClass myWebMethod() {
        myReturnClass o = new myReturnClass();
        o.myProperty1 = "a value";
        o.myProperty2 = "another value";
        return o;
    }
}

You need to add reference to this web service to your ASP.NET page. This is achieved in exactly the same way as before...

<atlas:ScriptManager ID="myScriptManager" runat="server" EnablePartialRendering="true" >  
  <Services>        
    <atlas:ServiceReference Path="~/myWebServiceURL.asmx" />    
  </Services>
</atlas:ScriptManager>

You can now make JavaScript calls to the web service as shown below...

<SCRIPT language='javascript'>
  myWebService.myWebMethod(s,myWebMethod_callback);

  function myWebMethod_callback(result)
  {
    alert("result.prop1="+result.myProperty1+"\nresult.prop2="+result.myProperty2);
  }
</SCRIPT>

I was very impressed that the properties of the c# class are now available to me in javascript. I hope you are too.

I have to say, credit goes to Paul Hayman who originally pointed this out to me. Credit also to the ATLAS team of course!

kick it on DotNetKicks.com del.icio.us digg Mister Wong YahooMyWeb Reddit Furl Spurl blogmarks
Dave Howard Skype
Author : Dave Howard
Published : Friday, 25 August, 2006

I have been involved in IT development for the last 10 years - a lot of it around desktop applications and telecoms.

Add Comment

Enter your comment below and it will be submitted for moderation.

Your Name

Add Tag

Please enter tags for this article, seperated by semi-colon ;

View Tag's by : # articles | # views