Simple custom service implementation example

Here is a simple calc custom service implementation for Dynamics 365 for Operations (aka AX7):
Main contract:
class VKOCalcContract
    int                 arg1;
    int                 arg2;
    VKOCalcOperation    operation;
    VKOCalcSubContract	subCalc;
    List                subList;

    public int parmArg1(int _arg1 = arg1)
        arg1 = _arg1;
        return arg1;

    public int parmArg2(int _arg2 = arg2)
        arg2 = _arg2;
        return arg2;

    public int parmOperation(int _operation = operation)
        operation = _operation;
        return operation;

    //This parm is just for demonstration on how you can use nested contracts and lists
        AifCollectionTypeAttribute("_list", Types::Class, classStr(VKOCalcSubContract)),
        AifCollectionTypeAttribute("return", Types::Class, classStr(VKOCalcSubContract))]
    public List parmSubList(List _subList = subList)
        subList = _subList;
        return subList;

    //This parm is just for demonstration on how you can use nested contracts and lists
    public VKOCalcSubContract parmSubCalc(VKOCalcSubContract _subCalc = subCalc)
        subCalc = _subCalc;
        return subCalc;
Sub contract. It is not used by the service, only to show the possibilities:
class VKOCalcSubContract
    int a;

    public int parmA(int _a = a)
        a = _a;
        return a;
Response contract:
class VKOCalcResponseContract
    real result;

    public real parmResult(real _result = result)
        result = _result;
        return result;
class VKOCalcService
    public VKOCalcResponseContract calc(VKOCalcContract _calcContract)
        VKOCalcResponseContract response    = new VKOCalcResponseContract();
        real                    result;
        int                     a1          = _calcContract.parmArg1(),
                                a2          = _calcContract.parmArg2();

        switch (_calcContract.parmOperation())
            case VKOCalcOperation::add:
                result = a1 + a2;
            case VKOCalcOperation::sub:
                result = a1 - a2;
            case VKOCalcOperation::multiply:
                result = a1 * a2;
            case VKOCalcOperation::divide:
                result = a1 / a2;

        return response;

Additionally you will need to
- create service pointing to the service class with service operation pointing to the calc method of service class.
- create service group holding created service

How to test custom services using RAW http.

Example of JSON request:
         "arg1": 2,
         "arg2": 2,
         "operation": 0,
         "list": [{
             "a": 0,
             "a": 1,
         "subCalc": {
             "a": 5
Example of answer:


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