Home > X++ stuffs > Dynamics AX2012: Create Custom Service using X++

Dynamics AX2012: Create Custom Service using X++


Case Study: In this demo scenario, we create a custom service to find the inventory onhand physical item quantity from AX2012.

To expose any Custom Service, method should be ‘public’ Access Specifiers & should be defined by an attribute named ‘[SysEntryPointAttribute(true)]’.



For this project, I have a created a sample InventoryOnHand service which basically returns the number of qty for a given Item.

class InventOnhandService
{
}

[SysEntryPointAttribute(true)]
public InventQty itemOnHandPhysical(ItemId  _itemId = '')
{
    SalesLine       salesLine;
    InventOnhand    inventOnHand;
    InventMovement  movement;
    InventQty       qty = 0;

    select firstOnly salesLine
        where salesLine.ItemId == _itemId;

    if (salesLine)
    {
        movement     = InventMovement::construct(salesLine);
        inventOnhand = InventOnhand::newPhysicalUpdate(movement, 
                                                       movement.inventdim());

        qty          = inventOnHand.availPhysical();
    }

    return qty;
}


Next step is to create a ‘Service’ & map the custom class with newly created service. By which you could exposed all public methods which are in the scope of current class. Please proceed further by Creating a New Service Group & Add it to Service Node Reference. Please mark the ‘Auto Deploy’ property to ‘Yes’ on the Service group (properties).

Right click on the created Service group and click ‘Deploy Service Group’. This would deploy all the relavent artifacts to the Inbound port under System Administration module.


In order to test your custom Service application, simply start VS Command prompt (or) traverse through Start -> AllPrograms -> Microsoft Visual Studio 2010 -> Visual Studio Tools -> Visual Studio Command Prompt

Enter wcftestclient, space and then paste the WSDL URI (which you can find on the deployed Inbound port)



When the WCF test client starts double click on your method ‘itemOnHandPhysical'(in my case) and specify the value under request by passing the _itemId (i.e. 1290 in my case) the invoke function will return the appropriate response of the available physical quantity of an item from the AX2012.



Download Link: InventoryOnHandService happy servicing AX2012 🙂

Advertisements
  1. March 19, 2013 at 5:49 pm

    Hi santosh,

    i need to return item details with category hiearchy when item id is passed …Could you please let me know how could we achieve this..

    Please help me on this…

  2. November 8, 2012 at 2:34 pm

    What do you think is the best way for calling services between multiple AOS servers? I have to contact different AOS servers that are connected to different databases from an central AOS server and each time the same document service. The same Model is used on all AOS servers.

  3. January 25, 2012 at 2:59 pm

    Useful article Santosh!!! Keep blogging for Ax2012…

    • mhamdaoui
      May 10, 2012 at 8:36 pm

      Hello, This is very helpful. I want to call this service, using HTTP and I can’t find how. What is the asmx url for a web service created in AX? Could you help me please?

      • May 28, 2012 at 1:19 pm

        Hey Thanks!!!

        What is your requirement?

  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: