Web services allow easy communication and data exchange in a secured environment. In Microsoft Dynamics NAV 2009 or above , you can create, publish, and consume Web services. For example, you can publish a Web service that lists all your customers and have that Web service immediately available for authorized requests over the network.
This walkthrough provides an overview of how to create and consume a simple Web service with Microsoft Dynamics NAV. The walkthrough illustrates to the following tasks:
To complete this walkthrough, you will need:
The first step is to create a codeunit that can be published and used as a Web service. You will create a codeunit called Letters that takes a lowercase input string and returns a string that is converted to uppercase letters.
After the codeunit is created and saved, register and publish it using the RoleTailored client.
You should verify that the Web service that you published is available to consumers. Check that Web services are running, and then browse to the WSDL document to ensure that your Web service is available.
If the service is already running, then you must restart it.
The page should list the Web service that you just published (Codeunit/Letters).
Now that the Web service is available, you can create an application to call the Web service.
The sample code in this walkthrough expects this exact application name, so do not change it.
C#
using System;
using System.Collections.Generic;
using System.Text;
namespace UsingLettersService
{
// Import newly generated Web service proxy.
using WebService;
class Program
static void Main(string[] args)
// Create a new instance of the service.
Letters ws = new Letters();
// Use default credentials for authenticating
// against Microsoft Dynamics NAV.
ws.UseDefaultCredentials = true;
// Declare variables to work with.
string inputstring, outputstring;
inputstring = “microsoft dynamics nav web services!”;
// Call the Microsoft Dynamics NAV codeunit Web service.
outputstring = ws.Capitalize(inputstring);
// Write output to the screen.
Console.WriteLine(“Result: { 0}”, outputstring);
// Keep the console window open until you press ENTER.
Console.ReadLine();
}
8. Press F5 to run the application in debug mode. You should see a console window that prints the text ‘MICROSOFT DYNAMICS NAV WEB SERVICES!‘ in uppercase letters.
9. Press Enter to close the application
You must be logged in to post a comment.
WhatsApp us