Creating custom service based on AifXmlSerializable class

AifXmlSerializable class

class VKOVAifXmlStr implements AifXmlSerializable
    str             xmlStr;


/// <summary>
///    Deserializes the xml to initialize the object.
/// </summary>
/// <param name="xml">
///    The xml to deserialize.
/// </param>
void deserialize(AifXml xml)
    XmlTextReader xmlReader;

    xmlReader = XmlTextReader::newXml(xml);

    // turn off Whitespace handling to avoid extra reads

    while ((xmlReader.nodeType() != XmlNodeType::Element) && !xmlReader.eof())

    xmlReader.readStartElement3(#MyDataObjectRoot, #MyDataObjectNS);
    if (!xmlReader.eof() && xmlReader.isStartElement())
        xmlStr = xmlReader.readElementString3('xml', #MyDataObjectNS);


public void fillXML(XmlTextWriter xmlTextWriter)
    xmlTextWriter.writeElementString('xml', xmlStr);

/// <summary>
///    Returns the name of the root element of the xml document.
/// </summary>
/// <returns>
///    The name of the root element of the xml document.
/// </returns>
public AifDocumentName getRootName()
    return #MyDataObjectRoot;

/// <summary>
///    Gets the schema of the xml document.
/// </summary>
/// <returns>
///    The xml schema that describes the document.
/// </returns>
AifXml getSchema()
    str schema =
    @'<?xml version="1.0"?>
    <xsd:schema xmlns=""
    <xsd:complexType name="VKOVAifXmlStrType">
    <xsd:element name="xml" type="xsd:string" />
    <xsd:element name="VKOVAifXmlStr" type="VKOVAifXmlStrType"/>

    return schema;

public void new()
    xmlStr = @'<?xml version="1.0" encoding="UTF-8"?>

public str parmXml(str _xml = xmlStr)
    xmlStr = _xml;

    return xmlStr;

public str parmXmlAdd(str _xml = '')
    if (_xml)
        xmlStr = _xml + xmlStr;

    return xmlStr;

/// <summary>
///    Serializes an object into xml.
/// </summary>
/// <returns>
///    The xml that represents this object instance.
/// </returns>
AifXml serialize()
    str xml;
    XmlTextWriter xmlTextWriter;


    xmlTextWriter = XmlTextWriter::newXml();

    // turn off indentation to reduce file size

    // initialize XML document

    // write root element
    xmlTextWriter.writeStartElement2(#MyDataObjectRoot, #MyDataObjectNS);

    // write custom data

    // serialize XML document into XML string
    xml = xmlTextWriter.writeToString();

    return xml;

Service class

RunOn property of class should be set to Server

class VKOVAifXmlStrService

public VKOVAifXmlStr makeRequest(str _xmlStr)
    VKOVAifXmlStr      xmlTest = new VKOVAifXmlStr();


    return xmlTest;


Create service VKOVAifXmlStrService with following properties:
1. Namespace:
2. Class: VKOVAifXmlStrService
Expand Operations node and Add operations, which is makeRequest.

Service Group

1. Create new one with name VKOVCustomServicesXml.

2. Right click and New Service Node Reference

3. Select VKOVAifXmlStrService as Service property and name

4. Deploy Service group

Check service Inbound ports: System administration -> Setup -> Services and Application Integration Framework -> Inbound ports

Test service

1. Run Visual Studio x64 Win64 Command Prompt 2010 / Open VC2012 x64 Native Tools Command Prompt
2. Run wcftestclient in Command Prompt
3. File -> Add service. Paste WSDl URI and click OK
4. Invoke test request
You also can use SoapUI


About is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags