Copy link to clipboard
Copied
Fellow devs,
I'm trying to call a web service by passing a SOAP parameter/header to the method, using the following code:
import mx.rpc.soap.*;
import mx.core.*;
import mx.rpc.events.*;
import fl.data.DataProvider;
import com.adobe.crypto.WSSEUsernameToken;
var myWebService = new WebService();
myWebService.addSimpleHeader
("header3", "http://www.w3.org/2001/XMLSchema", "symbol","MSFT");
myWebService.addEventListener("load", loadDone);
//myWebService.loadWSDL("http://www.webservicex.net/country.asmx?WSDL");
myWebService.loadWSDL("http://www.webservicex.net/stockquote.asmx?wsdl");
var myOperation:Operation;
function loadDone(evt:LoadEvent)
{
myOperation = Operation(myWebService.getOperation("GetQuote"));
myOperation.addEventListener("fault", wsError);
myOperation.addEventListener("result", wsResult);
myOperation.send();
}
function wsError(evt:FaultEvent)
{
}
function wsResult(evt:ResultEvent)
{
var xml:XML = XML(evt.result);
Test.text = xml.toString();
}
If I just run that code without dealing with parameter/header (see commented out line), it runs fine. But when I try to pass in a parameter via addsimpleheader, it always returns "exception". The web service country.asmx returns all countries; it doesn't need any parameters. That's the one that works fine, without the addsimpleHeader. But stockquote.asmx requires you to pass in a parameter, which is why I'm trying to get addsimpleHeader to work.
Any suggestions?
Thanks,
Alan
Copy link to clipboard
Copied
What I understand is, you want to pass parameter to a SOAP webservice.
If this is right, you don't need headers to pass arguments to a web-method. The operation has a request:Object property that is used to set the arguments to be passed to the service.
For example
var obj:Object=new Object()
obj[parameterName1]=parameterValue1
obj[parameterName2]=parameterValue2
.
.
.
and finally
myOperation.request=obj
This can also be set by the <mx:Request> .... </mx:Request> within the <mx:Operation /> tag.
Hope this solves your problem.
If you don't mind, may I ask why you are not using DCD wizard to connect to the webService. It is much easier that way !!!
http://flexedup.wordpress.com/2009/10/06/connecting-to-webservices-using-the-data-centric-development-dcd-feature-in-flash-builder-4/
This might help you !
Thanks
Balakrishnan V