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
- Connect to Microsoft NAV 2013 server with remote desktop connection. In our case the remote IP is 192.168.150.11, domain stud\ and username: prog1 and password: Password1! password is case-sensitive.
Open the Microsoft Dynamics NAV Windows client, and then connect to the CRONUS International Ltd. company.
In the Search box, enter Web Services, and then press Return.
In the Web Services page, choose New.
In the Object Type column, select Page, and then enter 21 in the Object ID column and Customer in the Service Name column.
Mark the check box in the Published column.
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
Start Windows Internet Explorer.
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
In Visual Studio, on the File menu, point to New, and then choose Project.
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
- Choose OK to close the New Project page.
- In Solution Explorer, right-click References in the project, and then choose Add Service Reference.
- 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
http://192.168.150.11:7047/DynamicsNAV70/WS/CRONUS%20Finland%20Oy/Services, and then choose Go.
- When the Customer service is displayed, choose View Service, rename localhost to CustomerService, and then choose Add Reference.
- In Solution Explorer, right-click add -> new item and in the Web tab select Web Form. You may rename it if you like.
- 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
- 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.
- Next modify the WebForm1.aspx.cs file.
- Firstly, remember to put "using CustomerService;" inside the namespace, otherwise the service will not be included in the code.
- 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()
- PrintCustomerList() and PrintCustomer() are used for printing the list of customers into a string. Customers are read into an array before printing.
- 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.
- 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.
- 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.
- 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.
- After this code is ready run the program in web browser, Bitch! You now have a web page that uses a NAV WebService.
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.