I am not sure whether it is intentional or not, but it certainly needs some attention.
My actual goal was to abort a Web Method Call after it has been invoked. We know that all kinds of Client Side Web Service Proxy are inherited from Sys.Net.WebServiceProxy class. This class contains a single method invoke which is used to call the server side method. The Ajax Documentation specifies that invoke method returns a Sys.Net.WebRequest class, which is used to call the method as well as aborting the call. So I came with following code:
var _webRequest = null;
function invokeMethod()
{
_webRequest = DataService.LongOperation ( 10000, //10 seconds
function(result)
{
alert(result);
$get('btnInvoke').disabled = false;
$get('btnAbort').disabled = true;
},
function(exception)
{
alert(exception.get_message());
$get('btnInvoke').disabled = false;
$get('btnAbort').disabled = true;
}
);
//_webRequest is undefined here !!!!
$get('btnInvoke').disabled = true;
$get('btnAbort').disabled = false;
}
function abortMethod()
{
if (_webRequest != null)
{
var executor = _webRequest.get_executor();
if (executor.get_started())
{
executor.abort();
}
$get('btnInvoke').disabled = false;
$get('btnAbort').disabled = true;
}
}But unfortunatly I found that the _webRequest is undefined. So I did a /js thing to generate the proxy:
var DataService=function() {
DataService.initializeBase(this);
this._timeout = 0;
this._userContext = null;
this._succeeded = null;
this._failed = null;
}
DataService.prototype={
LongOperation:function(miliseconds,succeededCallback, failedCallback, userContext)
{
return this._invoke(DataService.get_path(), 'LongOperation',false,{miliseconds:miliseconds},succeededCallback,failedCallback,userContext);}
}
DataService.registerClass('DataService',Sys.Net.WebServiceProxy);
DataService._staticInstance = new DataService();
//Removed the other parts for clarity
DataService.LongOperation= function(miliseconds,onSuccess,onFailed,userContext)
{
DataService._staticInstance.LongOperation(miliseconds,onSuccess,onFailed,userContext);
}
What I understand looking at the above code, the proxy contains a self instance as _staticInstance which is basically used to invoke the method (The Prototype seciton) and it returns the WebRequest properly. But what I do not understand why override function does not inculde the return keyword. it should be like this:
DataService.LongOperation= function(miliseconds,onSuccess,onFailed,userContext)
{
return DataService._staticInstance.LongOperation(miliseconds,onSuccess,onFailed,userContext);
}So to get the WebRequest I have to call the DataService._staticInstance.LongOperation instead of DataService.LongOperation().
Can any of the Ajax Team members shed a light on this? Is it a bug or intentional, if it is intentional then what is the reason?