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)

Error handling in methods exposed as AIF service

(0) ShareShare
ReportReport
Posted on by 345

Hi

I have been programming a couple of methods/operations that are exposed via an Inbound Port as a service.

One of these methods contains a transaction that should either complete successfully or roll back and return additional information. Under normal circumstances, this would be an easy job using Try-Catch, Throw an Error, and in the catch-block gather the additional information’s.

However this been AIF it seems that the framework encapsulates the session in an outer transaction with its own “Try-Catch” and any Throw or TTSAbort is handled by this.

The problem is that in my case the “rollback” is actually a valid result and I just need to send back some other information to the calling part.

Anyone have any idea how to handle this?

I have thought of two myself but are interested in any outside comments:

  1. Instead of using regular Transactions in my method I could use UserConnections but that would be a massive job since there are multiple methods involved

  2. Have my caller take care of the error handling and if he encounter an Exception, catch that and call a different operation for the additional information. This sound most feasible but the error thrown from AIF will end up in the AX Exception log as an error and there will be quite many when we are running operation.

Thanks

Thomas

 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at

    Here is a solution for your issue:

    dotnet-posts.blogspot.hu/.../exposing-ax2012-business-logic-and-data_16.html

    You may check the current application TTS level, and if it is greater than 0, commit the transaction first to close the default AIF block. After that you can do your own try-catch and exception handling. You can also include messages for your port to be sent back to the caller with the AIFFault class.

  • Thomas Vogt Poulsen Profile Picture
    345 on at

    That is amazing. Works like a charm.

    As you say I have to check the ttslevel at the start of my method before committing the outer transaction and I have to remember to start a new transaction as my method ends.

    Thanks

  • Patil Rohit Profile Picture
    on at

    Hi Thomas,

    I have a similar requirement. Could you help me with the code..

    Regards,

  • Thomas Vogt Poulsen Profile Picture
    345 on at

    Hi

    The below method should do the trick.

    [SysEntryPointAttribute(false)]

    public void serviceOperation()

    {

       int ttslevel;

       ttslevel = appl.ttsLevel();

       while (appl.ttsLevel() > 0)

       {

           ttsCommit;

       }

       // Call your methods and have your own error handling

       while (ttslevel > 0)

       {

           ttslevel--;

           ttsBegin;

       }

    }

  • Patil Rohit Profile Picture
    on at

    Appreciate the prompt response... Also I am looking to wrap the error in a response data contract from AIFFault class but cannot possibly figure out a way. Although, I can catch by marking the 'Include fault message' checkbox(Inbound port) from .NET but I would like to return in a contract response. Pls help.

  • Thomas Vogt Poulsen Profile Picture
    345 on at

    I would imagine that if you collect your error message and throw the entire message into default error handling it would follow the "Include fault message" check box. Maybe you can get a hit from this thread community.dynamics.com/.../822286

  • Patil Rohit Profile Picture
    on at

    Thank you Thomas i can now catch the error and return a custom message ... But I am failing to return the whole system message.

    For example I am populating my output response class something like this

    catch()

    {

      aifInfoLog = new AIFInfoLog();
      response.Error("Operation failed");
      response.ErrorDescription(aifInfoLog.getLastErrorMessage());
    
    }
    
    return response;

    Above I am trying to(the sited code is not correct) encapsulate the consolidated error/warning message at one go.

    Update:

    I am fetching the message from infolog using class

    SysInfologEnumerator   
    SysInfologMessageStruct

    which serves the purpose. Is there any better way?

    Regards,

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