clamp
clamp

Reputation: 34006

actionscript 3 soap webservices call method with parameters

i want to call a function on a soap-webservice using actionscript 3.

the function has multiple parameters each of different type (int string).

this is the as-code i have so far.

    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);
        }
    }

it fails because it doesnt have the necessay parameters provided which are defined by the webservice like this:

<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>

so my question is: how do i provide the parameters username, password, productid and languageCode to the method call?

Upvotes: 3

Views: 4217

Answers (1)

Vladimir Tsvetkov
Vladimir Tsvetkov

Reputation: 3013

WebService and RemoteObject share the same base class called AbstractService. The interface provides the method getOperation(name:String):AbstractOperation. My suggestion is to use the following construct:

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)); 

Upvotes: 3

Related Questions