As a dotnet developer you are used to passing and returning objects in your method calls this is a basic example that illustrates retreiving a simple object from a web method and passing an object to another.
this is the web service code
1: using System;
2: using System.Web;
3: using System.Collections;
4: using System.Web.Services;
5: using System.Web.Services.Protocols;
6:
7:
8: /// <summary>
9: /// This web service is the standard web service template that is added by visual studio 2005
10: /// </summary>
11: [WebService(Namespace = "http://tempuri.org/")]
12: [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
13: public class Service : System.Web.Services.WebService
14: { 15:
16: public Service () { 17:
18: //Uncomment the following line if using designed components
19: //InitializeComponent();
20: }
21:
22: /// <summary>
23: /// Gets a contact.
24: /// just simply instanciates the contact object populate it with server information
25: /// and return it
26: /// </summary>
27: /// <returns>an object of type Contact</returns>
28: [WebMethod]
29: public Contact GetContact()
30: { 31: Contact contact = new Contact();
32: contact.FirstName = "Jhon";
33: contact.LastName = "Doe";
34: contact.Email = "jhon.doe@silverkey.us";
35: contact.Id = 5;
36: return contact;
37: }
38:
39: /// <summary>
40: /// Gets the full name.
41: /// simply by concatinating the first name and lastname
42: /// </summary>
43: /// <param name="contact">A contact object passed by the client javascript.</param>
44: /// <returns>a string representing the Full Name </returns>
45: [WebMethod]
46: public string GetFullName(Contact contact)
47: { 48: return contact.FirstName + " " + contact.LastName;
49: }
50:
51:
52:
53: /// <summary>
54: /// this is a basic Class containning no logic
///just the properties needed
55: /// for transferring data
56: /// </summary>
57: public class Contact
58: { 59: private string _firstName;
60:
61: public string FirstName
62: { 63: get { return _firstName; } 64: set { _firstName = value; } 65: }
66: private string _lastName;
67:
68: public string LastName
69: { 70: get { return _lastName; } 71: set { _lastName = value; } 72: }
73: private string _email;
74:
75: public string Email
76: { 77: get { return _email; } 78: set { _email = value; } 79: }
80: private int _id;
81:
82: public int Id
83: { 84: get { return _id; } 85: set { _id = value; } 86: }
87:
88: }
89:
90: }
91:
All we need now is to have a web page that consumes this code
1: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
2:
3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
4: <html xmlns="http://www.w3.org/1999/xhtml">
5: <head runat="server">
6: <title>Untitled Page</title>
7: </head>
8: <body>
9: <form id="form1" runat="server">
10: <!-- you need the script manager control in all your pages -->
11: <!-- adding the services section is a refrence for your service -->
12: <!-- this is a refrence to the webservice that you need to consume-->
13: <!-- by adding this line you will have atlas prepare a proxy for -->
14: <!-- that you can use in Javascript-->
15: <atlas:ScriptManager ID="ScriptManager1" runat="server" >
16: <Services>
17: <atlas:ServiceReference Path="Service.asmx" GenerateProxy=true />
18: </Services>
19: </atlas:ScriptManager>
20:
21: <div>
22: <!-- these are just the buttons needed to call our functions -->
23: <input type=button runat=server onClick="invokeGetContact();"
value="getContact" /></br>
24: <input type=button runat=server onClick="invokeGetFullName();"
value="GetFullName" />
25: </div>
26: </form>
27: <script type="text/xml-script">
28: <page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
29: <references>
30: </references>
31: <components>
32: </components>
33: </page>
34: </script>
35: <script language=javascript>
36:
37: // the function that invokes the web service
38: // as the GetContact webmethod has no parameters
39: // we only need to pass the name of the function to invoke
40: // just after the webmethod returns from the server
41: function invokeGetContact(){ 42: Service.GetContact(getContactCallBack);
43: }
44:
45:
46: // this function is the fucnion that is invoked
47: // after the server returns
48: function getContactCallBack(results){ 49: var contact=results;
50: // debug.dump() is a method that writes
51: // the object hirarchy and values
52: // it's like a watch for your objects
53: debug.dump(contact);
54:
55: // as you can see this is a natural object behavior
56: // you can use the dot notation
57: debug.dump(contact.FirstName);
58: }
59:
60: // to send an object to the server you'll
61: // need to simulate the server class contact
62: // this is how a javascript class looks like
63: // most common mistake here is misspelling
64: function Contact(){ 65: this.Id; // Int
66: this.FirstName; // string
67: this.LastName; //string
68: this.Email;// string
69: }
70:
71:
72: // so basicall this will call the server webmethod
73: // just abc
74: function invokeGetFullName(){ 75: // a instantiate the object
76: var contact=new Contact ();
77:
78: // populate it
79: contact.Id=1;
80: contact.FirstName="Bill";
81: contact.LastName="Gates";
82: contact.Email="bill.g@microsoft.com";
83: // do the call one parametere for the server function so
84: // i pass it then the callback function name
85: Service.GetFullName(contact,getFullNameCallBack);
86: }
87:
88: // simple writes the string result of the webmethod
89: // should display "Bill Gates" :)
90: function getFullNameCallBack(results){ 91: debug.dump(results);
92: }
93:
94:
95: </script>
96: </body>
97: </html>
now all you need is find something to do with this code :)