Options

Error-handling when making Web Services

frandefrande Member Posts: 17
edited 2009-08-11 in NAV Three Tier
Hello,

I am currently working on designing a system that at first only should be runned on the NAV Classic client.
However in the short future we will proparly have to make it web-based too through Web Services.

I have a question on how the web-based system reacts if an ERROR(text) is made on a NAV codeunit-object.
Can I catch that error through and try-catch-sentence, or how to I do that?

I have been searching the WWW, but I cannot find any good explanations that helps me answer the question.

Thank you in advance,

Kristian.
Best regards,

Kristian

Answers

  • Options
    krikikriki Member, Moderator Posts: 9,096
    The webservices catches the error-message and sends it to the client who asked for the service in case the client waits for a reply from the webservice.
    Otherwise it just errors and the webservice stops running this request and waits for other requests.
    If you want to avoid the erroring, you can run a codeunit that runs the real codeunit is follows:
    IF CODEUNIT.RUN(CODEUNIT::"Codeunit to be run") THEN
      ....
    ELSE
      ...
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    frandefrande Member Posts: 17
    Hello kriki,

    Thank you for your response.

    As you said if the client waits for a reply from the webserver it will catch the error-message.
    Does it catch the error-message with a try-catch-statement, or?

    Thank you in advance,

    Kristian.
    Best regards,

    Kristian
  • Options
    ara3nara3n Member Posts: 9,255
    Yes if you need to catch at the client side that consumes the webservice, you need to do it with a try-catch-statement.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    and as an add-on to this answer all transactions are rolled back if an exception is raised when invoking code in web services.
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • Options
    krikikriki Member, Moderator Posts: 9,096
    freddy.dk wrote:
    and as an add-on to this answer all transactions are rolled back if an exception is raised when invoking code in web services.
    That means : EVEN IF YOU HAVE A COMMIT IN IT!

    We hit that bug. And we are proposing to make it into a feature! It can be really useful to have it also in the standard client. Especially if it works like LOCKTIMEOUT. There is also a fix for it.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Options
    frandefrande Member Posts: 17
    Hello,

    Thanks everybody for your help and your answers.

    Im guided in the right direction towards designing the application.

    Have a nice day!
    Best regards,

    Kristian
Sign In or Register to comment.