Dynamics Ax 2012 – AIF Import CSV File – Part 1: Consume Web service


I will start a series for AIF 2012 to use the Inbound port file adapter settings structured:

Part 1: Consume Web Service
Part 2: Create Item from File adapter
Part 3: Import CSV file with items Through AIF

The aim is to start from a web service to consume an AIF service, and then move that to a file system adapter. I will that take that a step further by adding a .Net transformation library so that we can import a CSV file to do the same. All throughout the process, there will be no change done within Dynamics Ax itself.

The service I am going to consume throughout the series is the InventItemService , and i will create an item.

With AX2012, we need to create a product and then release it. So for this demonstration, I will assume that the Products have been created, but have not been released yet.The AIF webservice InventItemService.create will do this for us.

Create and Consume web service:

I have found consuming AIF as web services easier than File adapter, which is why I start with this and then move this over to the File adapter.

Setting the AIF HTTP port to expose the InventItemService.Create:

Add InventItemService.create to the port

Once the Inbound port is activated, we can consume this in Visual studio. I shall create a Console application, and hard code the items to be created.

In Visual studio, add the service reference using the URI field of the Inbound Port.

static void Main(string[] args)
{
	//Initialise the Service
	using (LoonItemService.ItemServiceClient client = new LoonItemService.ItemServiceClient())
	{
		//Initizlise parameters used for the create method
		LoonItemService.CallContext callContext = new LoonItemService.CallContext() { Company = "ceu" };
		LoonItemService.AxdItem axdItem = new LoonItemService.AxdItem();

		LoonItemService.AxdEntity_InventTable inventTable = new LoonItemService.AxdEntity_InventTable();
		inventTable.ItemId = "SS001";
		inventTable.NameAlias = "SS001NAMEAlias";
		inventTable.Product = "SS001";

		List lstInventTable = new List();
		lstInventTable.Add(inventTable);
		axdItem.InventTable = lstInventTable.ToArray();

		//Call the AIF create method
		var result = client.create(callContext, axdItem);

		//Display the result
		foreach (var item in result)
		{
			foreach (var data in item.KeyData)
			{
				Console.WriteLine(string.Format("{0} : {1}", data.Field, data.Value));
			}
		}
	}
}

For a more detailed process on how to use the inventItemService.create look at this link: How to create an item using ItemServices and EcoResProductServices in AX 2012
On Running the code above, the Item is displayed in the Console, and if you check AX, the item SS001 is now a part of the Released products.

Item SS001 added to the released products

This is what we will replicate across to the File System adapter. in Part 2 and 3

Advertisements

10 thoughts on “Dynamics Ax 2012 – AIF Import CSV File – Part 1: Consume Web service

Leave a Reply / Comment

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