I'm currently communicating with an external SOAP service within AX using the a service reference and the generated .NET class. Everything is working out greatly with the exception of how to handle SOAP faults. Ideally, this doesn't happen, but sometimes the SOAP server (which I control as well) throws a SOAP fault with a "code" and a "message". Some examples of codes and their respective messages:
- "INVALID_API_KEY" / "An invalid API key was used."
- "INVALID_CUSTOMER_ID" / "An invalid customer Id was passed (%d)".
These error codes are defined in the WSDL, so when these faults are thrown I can naturally pass back some sanitized message to the user. Unfortunately, I'm having a problem drilling down through X++ to figure which SOAP fault has been thrown so that I can display back a sanitized explanation of failure back to my user. Currently my code looks like:
try
{
new InteropPermission(InteropKind::ClrInterop).assert();
// ... code making SOAP calls
CodeAccessPermission::revertAssert();
}
catch(Exception::CLRError)
{
warning(AifUtil::getClrErrorMessage());
}
This handles the SOAP fault well enough, the error it produces is the following: " Type 'System.ServiceModel.Channels.ReceivedFault' in assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable."
I have tried drilling down the base .NET classes, but the ServiceModel (and subsequently) the other classes for translating the SOAP fault (FaultException down the class ladder) into a human readable message are obscured.
Can anyone lend me some insight on how best to get at the actual fault code/message? Thanks!