web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Handling SOAP Faults

(0) ShareShare
ReportReport
Posted on by 5

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.  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 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!

*This post is locked for comments

I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Ali Zaidi Profile Picture

Ali Zaidi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans