这下又将操作委托给了Sys.Net.WebServiceProxy.invoke静态方法,继续看代码:
Sys.Net.WebServiceProxy.invoke = function Sys$Net$WebServiceProxy$invoke(
servicePath, methodName, useGet, params, onSuccess, onFailure, userContext, timeout) {
// validation omitted
...
// Create a web request to make the method call
var request = new Sys.Net.WebRequest();
// preparing request omitted
...
request.invoke();
function onComplete(response, eventArgs) {
// method body omitted
}
return request;
}嗨,这不就是我所需要的Sys.Net.WebRequest对象吗?原来想要得到这个对象那么简单,于是我就写下了下面的代码:
var request = DemoService.DemoMethod(onComplete);然后在必要时:
request.abort();
执行,出现了错误:request为undefined,为什么DemoMethod方法调用没有返回request对象?跟踪了代码之后,不大不小地晕了一下,原来问题出在这里:
DemoService._staticInstance = new DemoService(); ... DemoService.DemoMethod = function(onSuccess,onFailed,userContext) { DemoService._staticInstance.DemoMethod(onSuccess,onFailed,userContext); }
虽然早就知道Web Service代理会在类上创建一个Singleton对象,并且创建静态方法再委托给那个实例上的相应方法,却一直没有意识到这个细节。在上面的静态方法中,居然是直接调用了DemoMethod方法,却没有将结果返回出来,真让我哭笑不得了一下。
不过问题时非常轻易解决的,只要使用如下的方式在客户端调用WebService方法就可以了:
var request = DemoService._staticInstance.DemoMethod(onComplete);不过这个做法似乎……有些希奇?那么您也可以这样:
var demoService =
评论加载中…
![]() |