Search code examples
c#.netvb.netweb-servicesdynamics-nav

IndexOutOfRangeException when creating an Extension Codeunit for a Page Web Service


I'm trying to expose a Function in a Codeunit through a Page Web Service in Dynamics NAV (2009 R2). I followed the MSDN documentation and the steps in a blog post, but I'm getting the following error when connecting to the Web Service:

System.IndexOutOfRangeException: Index was outside the bounds of the array.

I've created a Page Web Service and a Codeunit Web Service, both using the same name, with only the Page Web Service published:

Web Services

My Codeunit contains only 1 Function for the moment and looks like this:

Codeunit

When I publish the Codeunit Web Service as well, I can use it, but the Page Web Service still shows the error.

When I rename the Codeunit Web Service, the Page Web Service works again as before, without the Codeunit's Functions, of course.

Am I missing something or doing something wrong?


Solution

  • Function in your codeunit have wrong signature. Moreover in the blog it is Run function that is used (not user function). Don't know if it's matters.

    Next phase: post the selected invoice. I don't have a method in my web service to post my invoice, so this is where we are going to extend the web service with this possibility. Very simple! I just created a codeunit with a function. In this function, the signature is important: the first parameter should be the same record variable of the page you published (in our case, "Sales Header"). This is my (only) function of my codeunit:

    PostInvoice(precSalesinvoice : Record "Sales Header") CODEUNIT.RUN(CODEUNIT::"Sales-Post", precSalesinvoice);