Web Service Transactions

igor.chladiligor.chladil Member Posts: 28
edited 2009-04-17 in NAV Three Tier
Hello,

I am using native web service in NAV2009 [GB Dynamics NAV 6.0, no hotfixes].
I have the web method that contains only the code below that should basically just "log something" in the InMsg table no matter whether there was an error in CU 99500 or not:
IF CODEUNIT.RUN(99500) THEN ;

InMsg.INIT;
InMsg."Message ID" := 'test';
InMsg.INSERT;

If there is no error in CU 99500 then the record is created in InMsg table as expected.

However if there is an error in CU 99500 the rest of the code in the method is performed (as expected), but the whole transaction seems to be rolled back and there is no record in InMsg table once the WS call finishes. If the same method is called from classic client, the record is created as expected.

Could somebody please explain to me why is this happenning and how can I make this code working as expected?

Thanks ahead,
Igor

Comments

  • kinekine Member Posts: 12,562
    Try to add explicit COMMIT at the end of the function. If I remember correctly, the commits during the webservice call are working differently than expected. May be there is some issue with that.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    COMMIT's in code in Web Services are just ignored - everything is committed when the web service returns - and everything is aborted if an exception occurs somewhere.

    It seems like the AL Exception handler doesn't work - meaning that the exception in your codeunit.run causes the Web Service to fail.
    I will investigate this and file a bug if that is the case.

    Have you tried outcommenting your if codeunit.run statement and verified that you actually get a log entry then?
    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.
  • kinekine Member Posts: 12,562
    Thanks Fraddy, I was not sure about the ignoring of the commits. May be using the CLEARLASTERROR after the CODEUNIT.RUN will help to clear the error and finish the webservice correctly... :-k
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • igor.chladiligor.chladil Member Posts: 28
    Thanks for your replies,

    I have tried to change the code to the following one but the result was the same:
    IF NOT CODEUNIT.RUN(99500) THEN
      CLEARLASTERROR;
    COMMIT;
    InMsg.INIT;
    InMsg."Message ID" := 'test';
    InMsg.INSERT;
    COMMIT;
    EXIT(100);
    

    IF the CU.RUN is commented out, the code works as expected - the record is inserted in NAV.

    According to me this behaviour is a bug as:

    1) Web Service returns without error and with correct return value (i.e. it has reached the end). Therefore I would expect the whole DB transaction to have been successful as well.
    2) Just the whole DB transaction seems to have been aborted.

    Regards,
    Igor
  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    It sure looks like a bug - we will look into it.
    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.
  • kinekine Member Posts: 12,562
    Igor, have you tried to use CLEARLASTERROR before exiting in case of some error in the codeunit? May be it will clear the error stack and it will not rollback the transaction...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • igor.chladiligor.chladil Member Posts: 28
    Yes, I have tried clearing the error after the CU Run.
  • hanskhansk Member, Microsoft Employee Posts: 2
    I have logged a bug on this issue.

    As the error is handled, there should be an implicit COMMIT when the Web service operation exits.

    Thanks for your help!

    /Hans
Sign In or Register to comment.