Advanced testing of Dynamics NAV web services



Creating web services in Dynamics NAV is really easy. Anyone who have tried it, knows that. However, testing them can prove a big challenge. Anybody with a Visual Studio and the knowledge of how to make a C# test program will probably mean that it is not a big problem, but for those don’t, there are a few tools - free or paid – that can help them out.


To create a web service, it is possible to use either existing pages or to create new pages to be used specifically with the web service. There are advantages and disadvantages with both solutions:





Creating new pages 1) Total control of which information that is published to the webservice
2) permissions can be applied specifically to the web service page 
1) Objects must be purchased for the purpose.
2) The new page must be developed specifically to the web service.
3) New fields added to the table must be manually added to the web service.
Using existing pages 1) No development and therefore no need to purchase extra objects 1) All information on the standard page will be included on the web service which means that if an Item Card page is published, the cost prices will also be published.


Because of the advantages of limiting the amount of fields and permissions on the page alone, I always create new pages for a web service.

Regarding the function web services it is always necessary to create one or more codeunits containing the functions for web services.




Because when a codeunit is published as a web service, ALL not local functions will be published as methods so we don’t want standard functions to be published. Also, if the functions are to be published with a page, it must be created as a separate codeunit.


But enough of that.


Enough bloggers have demonstrated how to create web services, so I am going to jump right in and create three types of web services:

  • List of sales orders
  • Post Sales Order function
  • Creating a new sales order

The Post Sales Order function will be published with the List of Sales Orders and the Create New Sales Order will be created with the XML port as the parameter.




Codeunit 80000 looks like this:



,codeunit 80001 looks like this:



and the XML port looks like this:



It is published as separate web services:



Everything looks cool, but does it work?


The first test is to see if it is running at all. In a standard Dynamics NAV installation, the web services are not activated by default, so that is the first thing to do:



The next thing it to check if the endpoint works. That can be done from the web services page in the RTC client. Just click the SOAP URL and something like this appears:



This means that the Dynamics NAV part of the publishing is OK.


Some perform the tests using the server name localhost. This can give problems later in the testing. Therefore, use the machine name and make sure to add the machine name to the Local Intranet security group in the Internet Options:



Next there is testing the actual functionality.


I have chosen to include three different tools:

  • InfoPath Designer, which is part of the Office Pro package
  • WS Studio: a small free tool to make simple tests of the web service
  • Postman, which is a free Google Chrome App for quite advanced test of the web services

InfoPath Designer

You might wonder what InfoPath is doing here, but truth is that I usually use InfoPath to demonstrate the possibilities with web services. It is especially effective if you are demonstrating web services to end-users:

  • Open InfoPath
  • Paste the end-point
  • Design the view
  • And show the result

Let us try:


Open InfoPath:



Choose Web Services



Paste the end-point and select the ReadMultiple operation:



Notice that because I published the page and the codeunit with the same name they are published together.


Drag the query fields to the top section and the SalesOrder section into the bottom section as a repeating table:




Go to the Form Options:



Set the Secutity and Trust to Full Trust



And click preview:



And here are all sales orders in the system.


If I had chosen to select only the Read method then it would look like this:



And the Preview looks like this:



Adding an extra Data Connection that points to the PostSalesOrder Method will allow me to add an extra button. I usually just copy the Run Query button and change the properties.



So here is the new data connection and here is the button:




First Run Query to retrieve the sales order and then Post Sales Order to post it.


All this took less than 10 minutes to create and demonstrate.


InfoPath was originally made to create forms that can be published both on the web and on SharePoint which also means that there are infinite possibilities there.

WS Studio

WS studio is another tool for doing simple tests of web services. The program is Open Source and can be downloaded here:


The user interface is simple and installation is only a matter of copying the program into a folder.

  1. Paste the end-point in the WSDL Endpoint field
  2. Click the Get button
  3. Select the desired Method
  4. Add the filter needed
  5. Click Invoke
  6. View the result




That’s it – No magic.


The limitations as I see them are primarily, that only one filter can be set at a time but other than that a very good little tool.



Postman is a free Google Chrome app which can perform very advanced web service tests. As the name suggest a prerequisite is that Google Chrome must be installed, but the program functions as a separate program. Postman supports testing of both SOAP and REST web services.


Postman can be downloaded from the Chrome Web Shop here.




After clicking “Add to Chrome” postman can be started:


At first glance it looks very simple. Paste the end-point into the field, change the method to post and click send:


This will show the web service definitions and I can give you a hint as how to apply filters.


But first a number of  parameters must be set up in order to receive data from the web service. First of all the content type. To find the content type, click the Headers (5) tab:


Copy the Content-Type into the Header field.


Then copy the namespace from the Body tab into the second header field:



Lastly, Click the Body tab select RAW format and enter the filters as shown:



Postman is a lot more complex than WS studio and not as user-friendly. However, the possibilities are endless.


One really great thing is, that it is possible to save the test for future use and even create collections of tests. Above I have created “My Collection” holding my test: Test Sales Orders. Another thing is that it is possible to export the tests and import them into another installation of Postman.


I have exported my example here and added it to my web site here.


An Example of a much more complicated test is the CreateSalesOrder function. Pasting the endpoint into Postman shows the following:



Now the same actions as previous must be performed to do the testing.




Here notice that the parameters are the key to the testing and also how I can test using structured data. In this case a Sales Header table and a number of Sales Lines.


Since the web service is a Dynamics NAV codeunit, it is necessary to add the Method, which is the same as the function name in Dynamics NAV. It is also necessary to state the xmlport namespace and define the structure manually:



Save the test and click Send


As the Return parameter I get the newly created order number and if we go to the sales orders in NAV, here it is:



There are many other tools. One is WCF Storm that can test either SOAP or REST web services. WCF Storm comes with a Lite version but in order to do some serious testing, it must be purchased. I will test that in a later post.


If you know of great testing tools for web services, then post a comment to this blog post.


Don’t be shy Smiley



  • Hi sir,

    In 80000, Web Service Functions, what is ReturnOrderNo, I did not find any property in the CAL Symbols


    Facing follwoing issue:


    Microsoft Dynamics NAV Development Environment


    You have specified an unknown variable.


    Define the variable under 'Global C/AL symbols'.




  • <a href="https:/">web design company</a>

    Nice blog and absolutely outstanding. You can do something much better but i still say this perfect.Keep trying for the best.