Contents

Handle AIF error messages in dynamics AX 2012 R3

Contents

Normally, when we consume AIF Service, we use this code like below to handle Error messages

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
try
{
	client.register(ctx, contract);
	Console.WriteLine("items registed on Trans Id: " + contract.InventTransId + " with " + contract.Qty + " quantities.");
	Console.ReadLine();
}
catch (Exception ex)
{
	Console.WriteLine(string.Format("Ex: {0}", ex.Message));
	Console.ReadLine();
}

If it cause error, message would return like this

/2017-01-12-handle-aif-error-messages-in-dynamics-ax-2012-r3/Handle-AIF-error-messages-in-dynamics-AX-2012-R3-1.png

If you want to know more details, you have to go In Dynamics ax AIF Exceptions form then check

/2017-01-12-handle-aif-error-messages-in-dynamics-ax-2012-r3/Handle-AIF-error-messages-in-dynamics-AX-2012-R3-2.png

It’s quite hard for 3rd party developer, especially they don’t have right to access AX server.

Anyway, we can get meaningful error message by doing below steps

  • Check that box in AIF inbound ports

/2017-01-12-handle-aif-error-messages-in-dynamics-ax-2012-r3/Handle-AIF-error-messages-in-dynamics-AX-2012-R3-3.png

  • Use FaultException class to get message
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
try
{
	client.register(ctx, contract);
	Console.WriteLine("items registed on Trans Id: " + contract.InventTransId + " with " + contract.Qty + " quantities.");
	Console.ReadLine();

}
catch (System.ServiceModel.FaultException<ItemsRegistration.RegRef.AifFault> aifFault)
{
	//FaultMessageList[] list = aifFault.Detail.FaultMessageListArray[0];
	InfologMessage[] list = aifFault.Detail.InfologMessageList;

	foreach (InfologMessage message in list)
	{
		Console.WriteLine(message.Message);

	}
	Console.ReadLine();

}

what we got

/2017-01-12-handle-aif-error-messages-in-dynamics-ax-2012-r3/Handle-AIF-error-messages-in-dynamics-AX-2012-R3-4.png

Thank you for reading.