Archive for September 2006

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’.