sotea
asked on
Wait for webservice response before returning value
I have a function that is getting some data from a webservice.
I would like to return the data, but the webservice has not responded when the 'return' statement is fired.
How do I wait for the webservice response???
========================== ========== ====
function IDLabel(myString1:String): String {
var stockservice = new WebService("http://localhost/...../mywebservice.asmx?WSDL", stockServiceLog);
stockservice.onLoad = function(wsdlDocument)
{
var pending:PendingCall = this.IDLabel(myString1, myString2);
pending.onResult = function(result)
{
if(typeof result.diffgram == "string"){
var p = new XML(result.diffgram);
} else {
var p = new XML(result.diffgram);
}
p.ignoreWhite = true;
_root.LokationID = p.firstChild.firstChild.fi rstChild.f irstChild. firstChild ;
//I tried placing the return statement here - but that doesn't work
}
stockResultObj.onFault = function(fault)
{
trace(fault.faultCode + "," + fault.faultstring);
}
}
return _root.LokationID;
}
I would like to return the data, but the webservice has not responded when the 'return' statement is fired.
How do I wait for the webservice response???
==========================
function IDLabel(myString1:String):
var stockservice = new WebService("http://localhost/...../mywebservice.asmx?WSDL", stockServiceLog);
stockservice.onLoad = function(wsdlDocument)
{
var pending:PendingCall = this.IDLabel(myString1, myString2);
pending.onResult = function(result)
{
if(typeof result.diffgram == "string"){
var p = new XML(result.diffgram);
} else {
var p = new XML(result.diffgram);
}
p.ignoreWhite = true;
_root.LokationID = p.firstChild.firstChild.fi
//I tried placing the return statement here - but that doesn't work
}
stockResultObj.onFault = function(fault)
{
trace(fault.faultCode + "," + fault.faultstring);
}
}
return _root.LokationID;
}
ASKER
Hi Iammontoya,
Thanks for the info - but I can't figure out how to implement it into my webservice call.
Could you show me, using the code I provided in my question...
Thanks for the info - but I can't figure out how to implement it into my webservice call.
Could you show me, using the code I provided in my question...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
onData (XML.onData handler)
onData = function(src:String) {}
Invoked when XML text has been completely downloaded from the server, or when an error occurs downloading XML text from a server. This handler is invoked before the XML is parsed, and you can use it to call a custom parsing routine instead of using the Flash XML parser. The src parameter is a string that contains XML text downloaded from the server, unless an error occurs during the download, in which case the src parameter is undefined.
It's actually pretty easy to use and if you pull up the help for onData you will see a simple example there: Looks like this...
XML.prototype.onData = function (src:String) {
if (src == undefined) {
this.onLoad(false);
} else {
this.parseXML(src);
this.loaded = true;
this.onLoad(true);
}
}