Generic AifXmlSerializable class
My goal with this project was to create an extended AifXmlSerializable class where the serialize, deserialize and getSchema methods where generic.
This makes the creation of an old service as easy as create as the 2012 wcf services. Why would you like to do this? First the Wcf services in Ax does not support the file or MQ adapter second I wanted to show that it’s not that hard to create an custom service that has an multiple level structure with methods in the form of other object or list’s.
This document will show how to implement a service with the AifExtXmlSerializable class and the AifExtList class which must be used for methods that that returns a list.
The scenario is a sales order service. By the way Dustin is the company i worked for :-).
1) Create the SalesOrder service class
public class DustinSalesOrderService
{
}
2) Create the service endpoint.
[SysEntryPointAttribute] public void Create(DustinSalesOrder _order)
{
ExecutePermission perm;
perm = new ExecutePermission();
perm.assert();
ttsBegin;
DustinSalesOrder::Create(_order);
ttsCommit;
CodeAccessPermission::revertAssert();
}
3) Create the SalesOrder class that is used as parameter för the service endpoint.
public class DustinSalesOrder Extends AifExtXmlSerializable
{
AifExtList salesOrderLines;
str sAccountNum; str sCurrency;
str sVATNum;
DustinAddress deliveryAddress;
DustinAddress invoiceAddress;
str sDlvDate;
str sOrdDate;
str sTotalLines;
str sSumTotal;
}
As you can see the extended list holds the SalesOrder lines and the same class is used for both delivery and invoice address.
public DustinAddress InvoiceAddress(DustinAddress _obj = invoiceAddress)
{
invoiceAddress = _obj;
return invoiceAddress;
}
public AifExtList SalesOrderLines(AifExtList _lst = salesOrderLines)
{
salesOrderLines = _lst;
return salesOrderLines;
}
Param methods do not have to have the prefix param and there is no need for a exist method. This means there will have to be some restrictions on the methods that are not to be use as parameter methods. None parameter methods must be of type static. Only elements present in the incomming payload will be marked as existing in the deserialize method.
public str AccountNum(str _s = sAccountNum)
{
sAccountNum = _s;
return sAccountNum;
}
static void Create(DustinSalesOrder _order)
{
//code
}
Instances of the classes used must be created in the new method of the master class in this case DustinSalesOrder. When lists are used you must specify the className which says what type of objects that the list contains.
public void new()
{
salesOrderLines = new AifExtList(Types::Class);
salesOrderLines.ClassName(“DustinSalesLine”);
deliveryAddress = new DustinAddress();
invoiceAddress = new DustinAddress();
super();
}
..Rest of the methods are not displayed as they look the same as the AccountNum method.
Each object used must extend the AifExtXmlSerializable class.
public class DustinSalesLine Extends AifExtXmlSerializable
{
str sLine;
str sItem;
str sDescription;
}
For objects that are to be used as List items must be set to isListItem = true in this case DustinSalesLine.
public void new()
{
this.isListItem(true);
super();
}
public class DustinAddress extends AifExtXmlSerializable
{
str sStreet;
str sStreetNumber;
str sPostBox;
str sISOcode;
str sZipCode;
str sCity;
str sLocation;
str sLocationName;
str sBuildingCompliment;
str sCountryRegionId;
str sDunsNumber;
DustinAddress dustinAddress;
}
As of yet i have not been able to set mandatory fields in any generic fasion. One idea has been to create a method in the AifExtXmlSerializable class named MandatoryFields that returns an container with mandatory fields name for the extended class.
Rename the file extension to xpo
Generic.AifXmlSerializable.01