Link to home
Start Free TrialLog in
Avatar of recruitit
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);
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ActionScript_Helper
ActionScript_Helper
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of recruitit
recruitit

ASKER

wierd, that fixed it for the local side but when it runs from the web browser it still doesnt work, ie if I click "run" on flash builder it works fine but if run off of a website it doesnt function, will do some more testing
after further testing I have discovered that the wsdl load event is not firing when its running from the web server, which is odd
scratch that, its not loading locally either now, even though it just worked :(
sorry forget that, it is working locally now, just not on the webserver from which the webservice is running
ah hah! added a FaultEvent handler, and this is the message I receive...

(mx.messaging.messages::ErrorMessage)#0
  body = (null)
  clientId = "DirectHTTPChannel0"
  correlationId = "D0CC2A52-C8E2-4A63-B16B-7C2DEBB87B0F"
  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-7C2DEC78FF44"
  rootCause = (flash.events::SecurityErrorEvent)#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
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
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-headers-from domain="www.website.com" headers="SOAPAction"/>
</cross-domain-policy>
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 :)
yea your right, sorry about that, my mind often encapsulates the whole issue