The SOAP protocol is designed to provide access to object's methods over the TCP connection. In the previous recipe, we published a NAV object, and now we will see how to consume the service provided by the published codeunit and call its methods.
In this recipe, you will create a project in Visual Studio to consume a NAV web service and call a codeunit method.
PostCodeWebServiceClient
.
http://localhost:7047/DynamicsNAV90/WS/Services
After entering the address, click the Go button located to the right of the URL field.
http://localhost:7047/DynamicsNAV90/WS/Codeunit/ApplicationManagement
in the list under Discovery Page, and click View Service:
PostCodeInfoService
and click Add Reference:
PostCodeInfoService
in your source code. Insert the using directive inside the project namespace PostCodeWebServiceClient
:namespace PostCodeWebServiceClient { using PostCodeInfoService; class Program {
Main
function, type the code calling the web service:PostCodeInfo postCodeInfo = new PostCodeInfo(); Console.WriteLine( postCodeInfo.GetCityByPostCode("BR 22291-040")); Console.ReadLine();
To access the NAV web service, we start a .NET project in Visual Studio and add a reference to the service interface. Basically, this is all we need to do to obtain access to the web service. Step 2 through Step 7 describe how to add a service reference to the project. When these steps are done, Visual Studio will automatically generate the set of proxy classes wrapping all service communication details and provide access to the classes through the namespace PostCodeInfoService
defined in Step 6.
The names of the classes available in the namespace match the names of web services published in NAV. The service we published is called PostCodeInfo
, so this will be the name of the class inside the PostCodeInfoService
namespace where the methods of codeunit 50800 Post Code Info
are exposed.
The only thing left to do after creating the service reference, is to instantiate the class PostCodeInfo
and call the method GetCityByPostCode
. The execution result will be shown in the console window.
18.119.167.196