Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.

 

 

 

 

 

 

 

Sys.Net.WebServiceProxy invoke Method

Invokes the specified Web service method.

Syntax

var webRequest = Sys.Net.WebServiceProxy.invoke(path, methodName, useHttpGet, parameters, succeededCallback, failedCallback, userContext, timeout);

Parameter

Description

path

The Web service URL. path can be set to a fully qualified URL (http://www.mySite.com/myService.asmx), to an absolute URL without the host name or the fully qualified domain name (FQDN) (/myService.asmx), or to a relative URL (../myService.asmx).

The WebRequest class makes sure that the URL is converted into a form usable by network executors.

methodName

The name of the Web service method to invoke.

useHttpGet

(Optional) false if the Web request HTTP verb is POST; otherwise, true. The default is false.

note

The call to the Web service will fail if the verb defined by useHttpGet does not match the ScriptMethodAttribute setting of the corresponding Web server method. For example, the following code (in C#) requires that the call be made with a GET verb:

[ScriptMethod(UseHttpGet=true)]

parameters

(Optional) A JavaScript dictionary that contains named properties (fields) that correspond to the parameters of the method to call, as in this example:

{"param1":196610,"param2":"Hello"}
note

The field names in the dictionary must match the names of Web service methods.

If the Web server method does not take any parameters, parameters can be left out or can be null or an empty dictionary ({}). Any values that you pass are then ignored.

If the dictionary contains key/value pairs that do not correspond to a parameter of the Web server method, they are ignored.

succeededCallback

(Optional) The function that is invoked as a callback if the Web service method call returns successfully.

succeededCallback can be set to null if you do not need it and if you must specify a value for the remaining parameters.

If no callback function is provided, no action is taken when the Web service method finishes successfully.

failedCallback

(Optional) The function that is invoked as a callback if the Web service method call fails.

failedCallback can be set to null if you do not need it and if you must specify a value for the remaining parameters.

If no callback function is provided, no action is taken if an error occurs during the Web service method call.

userContext

(Optional) Any user-specific information. userContext can be any JavaScript primitive type, array, or object.

The contents of userContext are passed to the callback functions (if any). If userContext is not provided, null is passed to the callback function.

timeout

(Optional) The time in milliseconds that the network executor must wait before timing out the Web request. timeout can be an integer or null. By defining a time-out interval, you can control the time that the application must wait for the callback to finish.

Return Value

The WebRequest instance that is used to call the method. This instance can be used to stop the call.

Remarks

The Web service path is assigned at run time, not through the path attribute of the <asp:ServiceReference> element of the <asp:ScriptManager> control in the page.

When you call the invoke method from JavaScript code, an asynchronous Web request is issued for the Web service method specified in methodName. When the request returns, the appropriate JavaScript callback function (succeeded or failed) is called, .

You do not have to pass callback functions or user context as parameters in the method call. Instead, you can specify default callback or user context settings as properties of the generated proxy object. For more information, see Generated Proxy Classes.

Example

The following example shows how to use invoke to call a Web service method.