.netaxaptadynamics-ax-2009business-connector

Returning XMLDocument from Ax2009


I have a function in Axapta as follows:

static client XMLDocument GetXmlData()
{
    XMLDocument xmlReturnDoc = new XMLDocument();

    // Build XML Document

    return xmlReturnDoc;
}

This returns an XML document. I’m then calling this from a .NET program using the business connector as follows:

Axapta ax;
object o;

ax = new Axapta();
ax.Logon(null, null, null, null);

o = ax.CallStaticClassMethod(“MyClass”, “GetXmlData”);

However, I don’t seem to be able to cast this to a System.Xml.XmlDocument in .NET. Is there a way to do this, or do I need to return a string and reload the document?


Solution

  • AX XMLDocument is not the same beast as CLR System.Xml.XmlDocument.

    There is no automatic conversion between object types. There are some implicit conversions of primitive types, but only one way. See How to: Marshal Between X++ and CLR Primitive Types.

    Reading How to: Call Business Logic Using .NET Business Connector leaves little doubt that the easy way is to return the XML string.