ServiceReference > Object

A static object used to create a single access point of a WebServiceRequest based Ajax call. Automatically provides Intellisense for parameters and return types and generates calls for synchronous and asynchronous calls.


AddCall(String functionName, String returnType, Parameters…) Adds a service function that can be accessed. For more see below.

Using a ServiceReference

ServiceReferences are created by using the WebServiceRequest.GenerateServiceReference method. From this, you can add specific calls to a service using the ServiceReference object. If AwesomeAjax-vsdoc.js is included in your scripts folder, you will get Intellisense support for whatever you add. Below is an example of the code and what it can produce. The names of the parameters that you provided MUST BE THE SAME NAME OF THE PARAMETERS ON THE WEB SERVICE SIDE. For example, if your Web Service in your ASP.NET application is as shown below:

public bool LogIn(string username, string password)
    // to do


Then then in your parameters portion of AddCall, they must be named “username” and “password” respectively as shown below.


Here we created a service reference that’s static. Now we have a static “UserService” object that we can attach static calls to.


As seen above, there is Intellisense showing a LogIn and LogInAsync function available from the new service reference.


Now you can see named parameters are available. For Async calls, you can provide a function or delegate to execute when onSuccess or onFail happens. Functions are provided an AjaxEventArgs argument for the first parameter, just like any other call.


Now, if you call the normal method, as you can see, we told AddCall that we would be returning a boolean value. After making the call, we get Intellisense for a Boolean value. For synchronous calls, the direct return type is provided. Keep in mind, you must do some error checking on your Web Service side in order to return safe values to your script, otherwise you can use the Async calls.

Last edited Oct 24, 2011 at 7:53 PM by dahrkdaiz, version 3


No comments yet.