flash webservices pending call gotcha – well got me for a while

I have a webservice running from asp.net. Sample method interface…

[WebMethod( Description = "Returns the About content" )]
public XmlDocument getAbout()
{
  xmlDoc.LoadXml( "<about></about>" );
  rootElement = xmlDoc.DocumentElement;
/*
* add some child nodes... etc
*/
...
  return xmlDoc;
}

As you can see the return type is of XmlDocument.

In ActionScript I am using code within a class similar to…

  private var myPCO :mx.services.PendingCall;
  private var myWSO :mx.services.WebService;

// myWSO is intialised once in a constructor or some other suitable location
  myWSO = new WebService( "/TheService.asmx?WSDL" );

//inside some function we initiate the data load
  myPCO = myWSO.getAbout();
  myPCO.onResult = mx.utils.Delegate.create( this, pcoResult )

// we handle a dataresult...
  private function pcoResult( result:XML ):Void
  {
    trace( result.firstChild.nodeName );
  }

The trace returns ‘undefined’. Spotted the mistake?

Because my service is returning an XML object, I assumed the ‘result’ would be the XML object. It isn’t. It is simply an object which contains the XML object, the root node of which you can access directly by name. In this case…

private function pcoResult( result:Object ):Void
{
  trace( result.about.nodeName );
}

This now correctly traces ‘about’.

Posted by creacog

Product Owner/Manager; Digital Project Manager, ex-Developer Available for Product Owner roles

1 comment

This is just what I needed to correctly ingest an XmlDocument object from a webService. Now I just need to figure out how to format XML to send to that same webService.

I am attempting to send an XML object and the webService returns “<undefined xmlns="http://ahtservices.com/webservices/&quot; />” when I attempt to load the XML I just sent. . . Any Ideas.

Do I need to wrap the XML in a generic object? I really just don’t know where to begin.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.