Handle AIF error messages in dynamics AX 2012 R3

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

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

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

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

  • Use FaultException class to get message
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

Thank you for reading.

Max Nguyen

Max Nguyen
MCP - Microsoft Dynamics AX Technical Consultant, currently living and working in Seoul, S.Korea :)