Hello -
I'm having a hard time figuring out how to add a header in Flex. I
need to pass a UserName and Password back to the Web Service in
order to get back the results. In this case the result is just an
XML which I then parsed and formated in Flash. Can anyone lend a
hand that has done it successfully? I went over the built-in help
but it isn't making a lot of sence to me. So far the only help I've
gotten is don't use the <WebService> tag. Here's what I used in
Flash 7 (and it works), maybe this will help someone help me convert
what I need -
// START WEB SERVICE CALL \\
function addSOAPHeaderFix() {
if (mx.services.PendingCall.prototype.__encodeSOAPHeader__ != null) {
return;
}
mx.services.PendingCall.prototype.__encodeSOAPHeader__ =
mx.services.PendingCall.prototype.encodeSOAPHeader;
mx.services.PendingCall.prototype.encodeSOAPHeader = function() {
var theService = this.myCall.wsdlOperation.wsdl.serviceProxy.service;
// here is how to do headers that apply to all calls
for (var i = 0; i < theService.headersForAllCalls.length; i++) {
this.addHeader(theService.headersForAllCalls);
}
// here is how to do headers that apply to only one specific call
for (var j = 0; j < theService.headersForOneCall.length; j++) {
this.addHeader(theService.headersForOneCall[j]);
}
theService.headersForOneCall = null;
this.__encodeSOAPHeader__();
};
}
addSOAPHeaderFix();
var service:mx.services.WebService;
service = new mx.services.WebService("http://radar.net/RadarXML.asmx?
WSDL");
var header1 = new XML('<AuthHeader
xmlns="http://tempuri.org/"><UserName>admin</UserName><Password>admin
</Password></AuthHeader>');
service.headersForAllCalls = new Array();
service.headersForAllCalls.push(header1);
var myObj:mx.services.PendingCall = service.PullXML();
//
// IF no fault has occured then XML is received \\
myObj.onResult = function(result) {
// change results to Flash XML \\
_global.theResults = new XML(result);
// strip out any white space \\
theResults.firstChild.stripWhite();
//load necessary script \\
loadAndSeperate();
};
// IF a fault occures get XML \\
myObj.onFault = function(result) {
_global.theResults = new XML();
theResults.ignoreWhite = true;
theResults.onLoad = function(success) {
loadAndSeperate();
};
// load the XML into the XML object
theResults.load("PublishXML/PublishedProjects.xml");
};
// END WEB SERVICE CALL \\