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)

Exception handling with Web Service (not catching)

(0) ShareShare
ReportReport
Posted on by 2,500

Hi,

After all these years I have encountered this problem where exceptions were handled differently.

Martin wrote about X++ and CIL.

http://dev.goshoom.net/en/2013/09/exception-handling-with-x-and-net-interop/

I wrote a custom web service with try/catch statements to see how it behaves.

After debugging I found it errored with unhandled ErrorException.

2017_2D00_01_2D00_31_5F00_14_2D00_39_2D00_44.png

The calling .NET console app catches the error as System.ServiceModelCommunicationException. This has the first error.

2017_2D00_02_2D00_03_5F00_16_2D00_38_2D00_30.png

The fact that AX does not respect the "catch" concerns me. What this is telling me is that I have to make my web service much more granular. Also, catching the errors in the calling application and dealing with it.

I wanted to see if others are experiencing the same or if any comments.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,987 Most Valuable Professional on at

    Check the transaction level - you can't catch errors inside transactions and custom services seem to be wrapped in transaction.

  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at

    It is TTS-related like Martin suggested, and not so long ago I've linked one possible solution here, similar to what the link above is suggesting:

    community.dynamics.com/.../225090

    Take a look and see if it helps to resolve your issue. Also I always like to tick the box for sending the AIF fault messages to the caller application in the port configuration, or wrap the error in a response data contract.

  • Munib Profile Picture
    2,500 on at

    Thanks to both that have responded. Below is a simple extract of what I am intending on doing.

    Hope it helps someone out there.

        boolean   ttsBeginCommitFound;
    
        //AIF does ttsbegin/ttscommit around the whole web service transaction. Commit it here
        while (appl.ttsLevel() > 0)
        {
            ttsCommit;
            ttsBeginCommitFound = true;
        }
        try
        {
            ttsBegin;
    	//do my thing here
            ttsCommit;
        }
        catch
        {
            //log my error and do my exception handling
        }
    
        //AIF does ttsbegin/ttscommit around the whole web service transaction. Do the Begin here
        if (ttsBeginCommitFound)
        {
            ttsBegin;
        }


  • Community Member Profile Picture
    on at

    Hi Ahmed,

    It works, but not in batch

  • Martin Dráb Profile Picture
    237,987 Most Valuable Professional on at

    I'm already discussing it with Tam Ngo in another answered thread, so let's not pollute the forum with duplicate questions.

    By the way, Tam Ngo, please don't mark your questions as suggested answers.

  • Community Member Profile Picture
    on at

    I would suggest using int ttsBeginCommitsFound; instead of boolean   ttsBeginCommitFound;. Count found ttsLevel and at the end replace

       if (ttsBeginCommitFound)

       {

           ttsBegin;

       }

    with

           while (ttsBeginCommitsFound)

           {

               ttsBegin;

               ttsBeginCommitsFound--;

           }

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
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans