Basic Tutorial of using NAV WebServices (Customer WebService)


1. Installed and working Microft Dynamics NAV 2013 server with SQL server

2. CRONUS International Ltd. demonstration database.

3. Visual studio 2013 recommended.

Publishing a page as a Web Service

  1. Connect to Microsoft NAV 2013 server with remote desktop connection. In our case the remote IP is, domain stud\ and username: prog1 and password: Password1! password is case-sensitive.

  2. Open the Microsoft Dynamics NAV Windows client, and then connect to the CRONUS International Ltd. company.

  3. In the Search box, enter Web Services, and then press Return.

  4. In the Web Services page, choose New.

  5. In the Object Type column, select Page, and then enter 21 in the Object ID column and Customer in the Service Name column.

  6. Mark the check box in the Published column.

  7. Choose OK to close the New - Web Services page.

It is recommended to test the connection after publishing the service

To verify availability of a Microsoft Dynamics NAV web service

  1. Start Windows Internet Explorer.

  2. In the Address field, enter an address of the following type: http://<Server>:<WebServicePort>/<ServerInstance>/WS/<CompanyName>/services. For example we used:

    Company name is case-sensitive

To call the web service

  1. In Visual Studio, on the File menu, point to New, and then choose Project.

  2. Expand the Visual C# node, select Web, .NET framework 4, and then select ASP.Net Empty Web Application. Enter a suitable name for the application. We used Web_Service_Test

  3. Choose OK to close the New Project page.

  4. In Solution Explorer, right-click References in the project, and then choose Add Service Reference.

  5. Choose the Advanced button, choose the Add Web Reference button, type or paste the URL that you used when you checked the WSDL, such as, and then choose Go.

  6. When the Customer service is displayed, choose View Service, rename localhost to CustomerService, and then choose Add Reference.

  7. In Solution Explorer, right-click add -> new item and in the Web tab select Web Form. You may rename it if you like.
  8. In Solution Explorer, select the newly created web form it will now show blank screen. From toolbox drag & drop new elements to your form we added two TextBoxes and two Buttons such as: CustomerBox with TextMode MultiLine, Textbox

    Layout Example

  9. CustomerBox will be used to print the customer list so it should be quite big. InputBox will be used to type in the name of a new customer (or a customer you want to delete) and the Buttons are for creating and deleting customers.

  10. Next modify the WebForm1.aspx.cs file.

    Code Example

  11. Firstly, remember to put "using CustomerService;" inside the namespace, otherwise the service will not be included in the code.

  12. Create a new class Program, for example. This will be used in the main program. There are four methods inside this class: PrintCustomerList(), PrintCustomer(), CreateCustomer() and DeleteCustomer()

  13. PrintCustomerList() and PrintCustomer() are used for printing the list of customers into a string. Customers are read into an array before printing.

  14. CreateCustomer() creates a new customer and gives it a name based on the parameter that the user specifies. DeleteCustomer() deletes the customer based on the name parameter. It does a filtered search based on the name and then deletes the correct customer.

  15. Then in the main program create a new instance of class Program, in this example we use a. Then create a new Customer_Service called service and the filters that are needed.

  16. In the Page_Load, Customer List is printed into CustomerBox using PrintCustomerList(). There is also an option to add filters to the list at this point. We have commented a basic name filter that prints only customers that begin with the letter C.

  17. CCustButton_Click() takes text from the InputBox and runs CreateCustomer() to create a new customer. The text in the InputBox will be the name of the customer. DCustButton_Click deletes the customer that is written in the InputBox.

  18. After this code is ready run the program in web browser, Bitch! You now have a web page that uses a NAV WebService.

    Application output

Adding more functionality to program

1. Customers need to have values in General Business Posting Group and Customer Posting Group so that they can be used in sales orders for example. Textbox for customer number is also needed so that it is possible to modify existing customers.

2. First add dropdown lists for both Posting Groups and add needed values into them. Then modify CreateCustomer() method to add the values into customers.

3. Add a Textbox for Customer Number and a Button for modifying customer.



4. Then you are ready to test the application again to see if it is working.

Last modified: Thursday, 5 December 2013, 5:55 PM