Is it possible to pass AIF exception messages to a C# client during document creation?

I am using the SalesSalesOrderService via an inbound AIF port to create a new sales order. I’m using the SalesOrderServiceClient::create() method in C# via a service reference in my project. The code itself is working; however, there are situations where an item is on hold or some other validation fails and thus the create method itself fails. Within the AX client I am able to locate the exception message and make sense of the failure; but, the C# client is left with a generic message which leaves no real option for robust client-side exception handling.

My question is this: is there a framework in place within AIF to propagate the warnings and errors that are generated during failure back to the C# client or is it necessary to implement custom X++ within the service to pass along the exception messages I’m looking for?

Thank you very much,

Scott Smith in Buffalo, NY, USA

I believe I may have found the answer I’m looking for. While debugging the C# client in VS 2015 I used intellisense to navigate through the exception object and found an InfologMessageList in the detail property of the exception. The InfologMessage objects in the list contain properties InfologMessageType and Message which appear to be the same information I’m seeing in the AX client’s Exceptions report.

I ended up being able to access the exception details by catching the exception type System.ServiceModel.FaultException. Just catching System.Exception ended up being a dead-end since there is no Detail property associated with it.

catch (System.ServiceModel.FaultException<AifFault> ex)
{
    var message = "";

    if (ex.Detail != null && ex.Detail.InfologMessageList != null && ex.Detail.InfologMessageList.Any())
    {
        message = ex.Detail.InfologMessageList.FirstOrDefault(m => m.InfologMessageType.Equals(InfologMessageType.Warning))?.Message;
    }

    client.Abort();

    throw new Exception(message);
}

This is a quick implementation inline with my AIF code and should be moved to another layer and/or extensions, but it illustrates the casting necessary to access the details. In this case I’m retrieving the first message of type InfologMessageType.Warning and then re-throwing its Message contents as a generic System.Exception for the next layer up to be able to handle without having a dependency on the AX namespaces or System.ServiceModel.