Options

Record Web Service Calls and Errors

jwilderjwilder Member Posts: 263
edited 2010-05-10 in NAV Three Tier
We have a Web Site that is calling NAV via Web Services (NAV 2009 SPI) for certain things such as Inventory Qty, Customer Comments etc...

I have created a web service log table in NAV that records the Function, Time, Parameters passed in and the return response. So when the website calls Web Services the first thing the function does in NAV is records this Web Service record.

My problem is that I am unble to record errors in the Web Service Log since upon error NAV rolls back. It does a great job of passing the error back to the calling web service but I am wondering if there is a way to capture the Error and record it to the log table that I created. An example of where this works is the Navision Timer 1.0 .dll that works nicely with a Single instance NAS Codeunit.

Comments

  • Options
    ara3nara3n Member Posts: 9,255
    are you 2009 or 2009 sp1?

    in 2009 commits were ignored and you can write your code in sp1

    if not codeunit.run and then
    get last error
    write it to log

    commit
    error(getlasterror);
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    jwilderjwilder Member Posts: 263
    SPI.

    Great suggestion and my current structure (Web Service Codeunit calling another codeunit's OnRun) can easily accommodate your suggestion. I'll try it out and get back to you.
  • Options
    kinekine Member Posts: 12,562
    Or you can use one "workaround". Create new table, save it. After that, switch the LinkedObject to true, and the newly displayed property LinkedInTransaction set to NO. This will exclude this table from the transactions and what you will save there it will be there even after rollback... ;-) CONS: NAV backup will not backup this table...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    jwilderjwilder Member Posts: 263
    Kamil good suggestion (I didn't know that) but the problem is I have no opportunity to save the error since there is no OnError trigger.

    ara3n your suggestion works but I was wrong about it flowing good with what I already have. To call Codeunit.Run requires quite a bit of restructuring with what I already have.

    All great suggestions, any other thoughts?
  • Options
    ara3nara3n Member Posts: 9,255
    I don't it requires a lot of restructuring.

    You can create a new Codeunit.

    create a new function in it called set parameters.

    Inside this codeunit call your existing codeuni on the run trigger.

    clear(newCU);
    newCU.setParameers(Customer, Comments, ItemNo., etc, etc);

    If not NewCu.run then begin


    end; else begin

    end;
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    jwilderjwilder Member Posts: 263
    I agree if it was just one Function being called it would not be a problem. But I have 7 Functions all with different parameters (and we will be adding more). An idea would be to add a SetParameter for each Datatype.

    The SetParameter functions certainly solves the problem I will keep it in mind but it just doesn't seem worth it at this point. It makes the code less clear and adds another codeunit to the process.

    Thanks for your help!
  • Options
    ara3nara3n Member Posts: 9,255
    Create a new function called insert Error log.

    In your webservice C# code write call this function in your code.


    Try
    {
    Webservice.callsomefunction;

    } catch

    {
    Webservice.insertlog(EventError);
    }
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.