recruitit
asked on
Flex WebService and HTTPService Result Event not firing when created programmatically.
When programmatically instantiating a WebService or HTTPService, the ResultEvent does not fire at all. Using the exact same settings but installed created declaratively in mxml works totally fine, its just when created in actionscript that it doesnt work.
// Programmatic declaration
public class ServiceProxy
{
private var service:WebService;
public function ServiceProxy(){
service = new WebService();
service.wsdl = "http://www.domain.com/service.asmx?wsdl";
// used for authentication
var qname:QName = new QNAME("http://www.domain.com/", "Header");
var header:SOAPHeader = new SOAPHeader(qname, {});
var content:XML = <AuthHeader insert xml here </AuthHeader>;
header.content = content;
service.addHeader(header);
// add the event listener
service.addEventListener(ResultEvent.RESULT, serviceResultHandler);
}
private function serviceResultHandler(event:ResultEvent):void{
}
public function runService(value:String):void{
service.methodName(value);
}
}
// mxml declaration
<s:WebService id="service"
wsdl="http://www.domain.com/service.asmx?wsdl"
result="webservice1_resultHandler(event)" />
protected function webservice1_resultHandler(event:ResultEvent):void{
}
protected function button_clickHandler(event:MouseEvent):void{
var qname:QName = new QName("http://www.domain.com/", "Header");
var header:SOAPHeader = new SOAPHeader(qname, {});
var content:XML = <AuthHeader xml goes here </AuthHeader>;
header.content = content;
service.addHeader(header);
service.methodName(value.text);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
after further testing I have discovered that the wsdl load event is not firing when its running from the web server, which is odd
ASKER
scratch that, its not loading locally either now, even though it just worked :(
ASKER
sorry forget that, it is working locally now, just not on the webserver from which the webservice is running
ASKER
ah hah! added a FaultEvent handler, and this is the message I receive...
(mx.messaging.messages::Er rorMessage )#0
body = (null)
clientId = "DirectHTTPChannel0"
correlationId = "D0CC2A52-C8E2-4A63-B16B-7 C2DEBB87B0 F"
destination = ""
extendedData = (null)
faultCode = "Channel.Security.Error"
faultDetail = "Destination: DefaultHTTP"
faultString = "Security error accessing url"
headers = (Object)#1
DSStatusCode = 0
messageId = "2DC3899D-C723-6BAB-7E05-7 C2DEC78FF4 4"
rootCause = (flash.events::SecurityErr orEvent)#2
bubbles = false
cancelable = false
currentTarget = (flash.net::URLLoader)#3
bytesLoaded = 0
bytesTotal = 0
data = (null)
dataFormat = "text"
errorID = 0
eventPhase = 2
target = (flash.net::URLLoader)#3
text = "Error #2048"
type = "securityError"
timestamp = 0
timeToLive = 0
(mx.messaging.messages::Er
body = (null)
clientId = "DirectHTTPChannel0"
correlationId = "D0CC2A52-C8E2-4A63-B16B-7
destination = ""
extendedData = (null)
faultCode = "Channel.Security.Error"
faultDetail = "Destination: DefaultHTTP"
faultString = "Security error accessing url"
headers = (Object)#1
DSStatusCode = 0
messageId = "2DC3899D-C723-6BAB-7E05-7
rootCause = (flash.events::SecurityErr
bubbles = false
cancelable = false
currentTarget = (flash.net::URLLoader)#3
bytesLoaded = 0
bytesTotal = 0
data = (null)
dataFormat = "text"
errorID = 0
eventPhase = 2
target = (flash.net::URLLoader)#3
text = "Error #2048"
type = "securityError"
timestamp = 0
timeToLive = 0
ASKER
ok lol, after alot of research I found out that you need to use a crossdomain.xml file like so...
<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="*" />
<allow-access-from domain="*.macromedia.com" secure="false" />
<allow-access-from domain="*.adobe.com" secure="false" />
</cross-domain-policy>
now, this fixed the LoadEvent, but the ResultEvent is still broken, the odd thing is that I no longer trigger the error during the loadWSDL but it now triggers when I call the webservice function
<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="*" />
<allow-access-from domain="*.macromedia.com" secure="false" />
<allow-access-from domain="*.adobe.com" secure="false" />
</cross-domain-policy>
now, this fixed the LoadEvent, but the ResultEvent is still broken, the odd thing is that I no longer trigger the error during the loadWSDL but it now triggers when I call the webservice function
ASKER
yeesh ok, its all finally working now, I had to modify the cross-domain-policy again to allow SOAPHeaders.
<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="www.website.com" secure="false" />
<allow-http-request-header s-from domain="www.website.com" headers="SOAPAction"/>
</cross-domain-policy>
<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="www.website.com" secure="false" />
<allow-http-request-header
</cross-domain-policy>
ASKER
Was half the answer :)
what you described in your question was that in MXML tags your were able to work with webservice but you were facing problem making it in ActionScript.
After getting actionscript to work you found another issue, which was not part of the question :)
Anyway, glad, you made it work :)
After getting actionscript to work you found another issue, which was not part of the question :)
Anyway, glad, you made it work :)
ASKER
yea your right, sorry about that, my mind often encapsulates the whole issue
ASKER