Microsoft Dynamics 365 Blog

This post describes how to call the AIF sales order service from X++ code.  The same approach can be used for calling any web service.

In the AOT under the References node add a service reference specifying the wsdl location of the service, a .NET code namespace and a reference namespace.  An example of a wsdl url is:


Once the reference has been created, in X++ create a new class that runs on the server.  In a method in the class write the code that calls the service.  An example of how to call the sales order service is below.  Once the code in the class compiles close the AX client.  Go to the Appl\Standard\ServiceReferences directory and copy the app.config and the generated assembly to the Server\bin directory.

    SalesOrder.SalesOrderServiceClient proxyClient;
    SalesOrder.AxdSalesOrder salesOrder;
    SalesOrder.AxdEntity_SalesTable salesTable;
    SalesOrder.AxdEntity_SalesLine salesLine;
    SalesOrder.AxdEntity_InventDim inventDim;
    SalesOrder.AxdEntity_InventDim[] inventDimArray;
    SalesOrder.AxdEntity_SalesLine[] salesLineArray;
    SalesOrder.AxdEntity_SalesTable[] salesTableArray;
    Exception ex;

       new InteropPermission(InteropKind::ClrInterop).assert();

        proxyClient = new SalesOrder.SalesOrderServiceClient();
        salesOrder = new SalesOrder.AxdSalesOrder();

        salesTable = new SalesOrder.AxdEntity_SalesTable();
        salesTable.set_DeliveryDate(str2date(“2/14/2010”, 0));

        salesLine = new SalesOrder.AxdEntity_SalesLine();
        salesLine.set_SalesQty(new System.Decimal(99));

        inventDim = new SalesOrder.AxdEntity_InventDim();

        inventDimArray = new SalesOrder.AxdEntity_InventDim[1]();
        inventDimArray.SetValue(inventDim, 0);

        salesLineArray = new SalesOrder.AxdEntity_SalesLine[1]();
        salesLineArray.SetValue(salesLine, 0);

        salesTableArray = new SalesOrder.AxdEntity_SalesTable[1]();
        salesTableArray.SetValue(salesTable, 0);


        info(“Sales order successfully created.”);


    catch (Exception::CLRError)
        throw error(AifUtil::getClrErrorMessage());


More Information

  • If you need to use a type that is not an AX type like System.Decimal you will have to call the assert method on the InteropPermission class before instantiating the type. 
  • In the Intellisense for the code editor arrays are not listed, only the singular instances of the types are displayed.  However, you can still add the arrays to your code and they will compile.  When you populate the arrays do it using syntax similar to the code example in this article where the array is first declared and the SetValue method is called to set the value and index for the entry in the array. 
  • If the assembly in the Application\Appl\<InstanceName>\ServiceReferences directory is not copied to the Server\bin directory you will get missing reference errors thrown at runtime when instantiating the arrays. 
  • If the app.config in the Application\Appl\<InstanceName>\ServiceReferences directory is not copied to the Server\bin directory CLRObject could not be created errors are thrown when trying to instantiate the first non-service client class so in the example in this article the line salesOrder = new SalesOrder.AxdSalesOrder() would throw a CLRObject exception.

We're always looking for feedback and would like to hear from you. Please head to the Dynamics 365 Community to start a discussion, ask questions, and tell us what you think!