Skip to main content

Notifications

Announcements

No record found.

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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Exception handling with Web Service (not catching)

    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--;

           }

  • Martin Dráb Profile Picture
    Martin Dráb 230,445 Most Valuable Professional on at
    RE: Exception handling with Web Service (not catching)

    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
    Community Member Microsoft Employee on at
    RE: Exception handling with Web Service (not catching)

    Hi Ahmed,

    It works, but not in batch

  • Munib Profile Picture
    Munib 2,500 on at
    RE: Exception handling with Web Service (not catching)

    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;
        }


  • Verified answer
    Vilmos Kintera Profile Picture
    Vilmos Kintera 46,149 on at
    RE: Exception handling with Web Service (not catching)

    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.

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,445 Most Valuable Professional on at
    RE: Exception handling with Web Service (not catching)

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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,391 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans