actionscript 3 soap webservices调用带参数的方法

时间:2011-10-27 12:20:53

标签: web-services flex actionscript soap

我想使用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>

所以我的问题是:如何在方法调用中提供参数username,password,productid和languageCode?

1 个答案:

答案 0 :(得分:3)

WebServiceRemoteObject共享同一个名为AbstractService的基类。界面提供方法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));