{infiniteZest}
// Articles. Tutorials. Utilities.
Home  |   Search  |   Login  
Categories Skip Navigation Links
New / All
AJAX
Apple
ASP.NET
.NET
Git
Google / Android
Python / IronPython
Miscellaneous
SQL Server
AJAX Source Viewer
View the source code of a Method from ASP.NET AJAX Library. Choose a method from the menu items above (Namespaces, Classes, or Methods).
Method 'invoke(servicePath, methodName, useGet, params, onSuccess, onFailure, userContext, timeout)'
Method: invoke(servicePath, methodName, useGet, params, onSuccess, onFailure, userContext, timeout)
Method Full Name:     Sys$Net$WebServiceProxy$invoke(servicePath, methodName, useGet, params, onSuccess, onFailure, userContext, timeout)
Class: WebServiceProxy
Namespace: Sys.Net
Source File: MicrosoftAjax.debug.js
1   Sys.Net.WebServiceProxy.invoke = function Sys$Net$WebServiceProxy$invoke(servicePath, methodName, useGet, params, onSuccess, onFailure, userContext, timeout) {
2     /// <summary locid="M:J#Sys.Net.WebServiceProxy.invoke" />
3     /// <param name="servicePath" type="String"></param>
4     /// <param name="methodName" type="String"></param>
5     /// <param name="useGet" type="Boolean" optional="true"></param>
6     /// <param name="params" mayBeNull="true" optional="true"></param>
7     /// <param name="onSuccess" type="Function" mayBeNull="true" optional="true"></param>
8     /// <param name="onFailure" type="Function" mayBeNull="true" optional="true"></param>
9     /// <param name="userContext" mayBeNull="true" optional="true"></param>
10    /// <param name="timeout" type="Number" optional="true"></param>
11    /// <returns type="Sys.Net.WebRequest"></returns>
12    var e = Function._validateParams(arguments, [
13    {name: "servicePath", type: String},
14    {name: "methodName", type: String},
15    {name: "useGet", type: Boolean, optional: true},
16    {name: "params", mayBeNull: true, optional: true},
17    {name: "onSuccess", type: Function, mayBeNull: true, optional: true},
18    {name: "onFailure", type: Function, mayBeNull: true, optional: true},
19    {name: "userContext", mayBeNull: true, optional: true},
20    {name: "timeout", type: Number, optional: true}
21    ]);
22    if (e) throw e;
23    var request = new Sys.Net.WebRequest();
24    request.get_headers()['Content-Type'] = 'application/json; charset=utf-8';
25    if (!params) params = {};
26    var urlParams = params;
27    if (!useGet || !urlParams) urlParams = {};
28    request.set_url(Sys.Net.WebRequest._createUrl(servicePath+"/"+encodeURIComponent(methodName), urlParams));
29    var body = null;
30    if (!useGet) {
31      body = Sys.Serialization.JavaScriptSerializer.serialize(params);
32      if (body === "{}") body = "";
33    }
34    request.set_body(body);
35    request.add_completed(onComplete);
36    if (timeout && timeout > 0) request.set_timeout(timeout);
37    request.invoke();
38    function onComplete(response, eventArgs) {
39      if (response.get_responseAvailable()) {
40        var statusCode = response.get_statusCode();
41        var result = null;
42        
43        try {
44          var contentType = response.getResponseHeader("Content-Type");
45          if (contentType.startsWith("application/json")) {
46            result = response.get_object();
47          }
48          else if (contentType.startsWith("text/xml")) {
49            result = response.get_xml();
50          }
51          else {
52            result = response.get_responseData();
53          }
54          } catch (ex) {
55        }
56        var error = response.getResponseHeader("jsonerror");
57        var errorObj = (error === "true");
58        if (errorObj) {
59          if (result) {
60            result = new Sys.Net.WebServiceError(false, result.Message, result.StackTrace, result.ExceptionType);
61          }
62        }
63        else if (contentType.startsWith("application/json")) {
64          if (!result || typeof(result.d) === "undefined") {
65            throw Sys.Net.WebServiceProxy._createFailedError(methodName, String.format(Sys.Res.webServiceInvalidJsonWrapper, methodName));
66          }
67          result = result.d;
68        }
69        if (((statusCode < 200) || (statusCode >= 300)) || errorObj) {
70          if (onFailure) {
71            if (!result || !errorObj) {
72              result = new Sys.Net.WebServiceError(false , String.format(Sys.Res.webServiceFailedNoMsg, methodName), "", "");
73            }
74            result._statusCode = statusCode;
75            onFailure(result, userContext, methodName);
76          }
77          else {
78            var error;
79            if (result && errorObj) {
80              error = result.get_exceptionType() + "-- " + result.get_message();
81            }
82            else {
83              error = response.get_responseData();
84            }
85            throw Sys.Net.WebServiceProxy._createFailedError(methodName, String.format(Sys.Res.webServiceFailed, methodName, error));
86          }
87        }
88        else if (onSuccess) {
89          onSuccess(result, userContext, methodName);
90        }
91      }
92      else {
93        var msg;
94        if (response.get_timedOut()) {
95          msg = String.format(Sys.Res.webServiceTimedOut, methodName);
96        }
97        else {
98          msg = String.format(Sys.Res.webServiceFailedNoMsg, methodName)
99        }
100       if (onFailure) {
101         onFailure(new Sys.Net.WebServiceError(response.get_timedOut(), msg, "", ""), userContext, methodName);
102       }
103       else {
104         throw Sys.Net.WebServiceProxy._createFailedError(methodName, msg);
105       }
106     }
107   }
108   return request;
109 }
This is the JavaScript source for method invoke(servicePath, methodName, useGet, params, onSuccess, onFailure, userContext, timeout) from ASP.NET AJAX Library. Full name for this method is Sys$Net$WebServiceProxy$invoke(servicePath, methodName, useGet, params, onSuccess, onFailure, userContext, timeout). It belongs to the class WebServiceProxy, which is in Sys.Net namespace. This source is in MicrosoftAjax.debug.js file.
Bookmark and Share This
About  Contact  Privacy Policy  Site Map