AJAX Client Side Programming
page 5 of 8
by Brian Mains
Feedback
Average Rating: 
Views (Total / Last 10 Days): 5943/ 324

Web Services

ASP.NET AJAX heavily uses web services to perform client-server communication.  There are multiple ways to create a web service that the client can connect with.  The one way I'll touch upon here is the System.Net.WebServiceProxy class.  This class is the proxy to make a call to a method on a web service.  Whether the web service succeeds or fails, the appropriate method call is made.

As a simple test, I defined a WebMethod inside of my page as such:

Listing 15

[WebMethod]
public static string GetOutput()
{
  return "Successful";
}

The following markup simply makes the call to the page method and supplies the label with the text value returned from the web service method, if no errors occurred.  Otherwise, if errors did occur, the text "Error" appears from the onFailure callback.

Listing 16

<script language="javascript" type="text/javascript">
      function pageLoad()
      {
            var wsProxy = new Sys.Net.WebServiceProxy();
            wsProxy.set_timeout(0);
            var label = $get("output");
            
            var request = wsProxy._invoke("http://localhost:61379/testloader.aspx", 
                  "GetOutput", false, {}, onSuccess, onFailure, label);
      }
      
      function onSuccess(result, userContext, methodName)
      {
            userContext.innerText = result;
      }
      
      function onFailure(result, userContext, methodName)
      {
            userContext.innerText = "Error";
      }
</script>
 
<span id="output"></span>

Running this page makes the call to the web service and returns the result to the label.  A nice feature of Visual Studio 2008 is that you can debug both the server-side and client-side call to ensure it works correctly.


View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 2 and 2 and type the answer here:

User Comments

Title: Nice Article   
Name: ---
Date: 6/21/2008 5:40:01 AM
Comment:
really nice article, it is good for the beginners.
good job :)
Title: dragpanel extender in ajax controls   
Name: lalitha
Date: 6/12/2008 5:46:21 PM
Comment:
its not working as i had written as it was mentioned here in the tutorial plse give a brief coding about that control
Title: expect more   
Name: sivaram
Date: 5/2/2008 4:50:01 AM
Comment:
ok .i expected more.If possible plz explain with the examples
Title: nice but shud little brief   
Name: snehal
Date: 4/30/2008 3:20:58 PM
Comment:
nice article but give more details on ajax its merits... funnalities future implementation ....etc thnx
Title: thanks   
Name: suhas kudekar
Date: 4/23/2008 9:02:58 AM
Comment:
its very new concept 4 me. thanks
Title: very good   
Name: panakj lahjoti
Date: 4/21/2008 7:34:42 AM
Comment:
hai
i found this aticle very useful for the newbies
Title: Very helpful   
Name: Raviraj
Date: 4/20/2008 1:28:30 PM
Comment:
thanks it is very helpful to me






Ads Powered by Lake Quincy Media
Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2008 ASPAlliance.com  |  Page Processed at 7/20/2008 8:08:29 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search