我想使用 actionscript 3 在 soap-webservice 上调用一个函数。
该函数有多个不同类型的参数(int string)。
这是我目前的代码。
var ws:WebService = new WebService();
ws.wsdl = "http://.../Service.svc?WSDL";
ws.addEventListener(FaultEvent.FAULT, faultHandler);
ws.addEventListener(LoadEvent.LOAD, wsdlLoaded);
ws.loadWSDL();
function wsdlLoaded(event:LoadEvent):void {
trace("loaded: " + event.toString());
ws.GameListGet.addEventListener(ResultEvent.RESULT, GameListGetHandler);
ws.GameListGet();
function GameListGetHandler(event:ResultEvent):void {
trace("ok"+event);
}
}
它失败了,因为它没有提供由 web 服务定义的必要参数,如下所示:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:service.com" xmlns:gre="http://schemas.datacontract.org/Common">
<soapenv:Header/>
<soapenv:Body>
<urn:GameListGet>
<!--Optional:-->
<urn:authentication>
<!--Optional:-->
<gre:Password>?</gre:NrgsPassword>
<!--Optional:-->
<gre:Username>?</gre:NrgsUsername>
<!--Optional:-->
<gre:ProductId>?</gre:ProductId>
</urn:authentication>
<!--Optional:-->
<urn:languageCode>?</urn:languageCode>
</urn:GameListGet>
</soapenv:Body>
</soapenv:Envelope>
所以我的问题是:如何为方法调用提供参数用户名、密码、productid 和 languageCode?p>
最佳答案
WebService
和 RemoteObject
共享同一个名为 AbstractService
的基类。该接口(interface)提供方法getOperation(name:String):AbstractOperation
。我的建议是使用以下结构:
var gameListGetOperation:AbstractOperation = ws.getOperation("GameListGet");
gameListGetOperation.arguments = [/*here you pass all needed arguments*/];
var token:AsyncToken = gameListGetOperation.send(); // this invokes the WS operation
// pass the callbacks to handle the result or fault
token.addResponder(new Responder(resultFunction, faultFunction));
关于web-services - 带参数的 actionscript 3 soap webservices 调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7915744/