Microsoft Dynamics NAV web service types
The NAV objects that can be exposed as web services are:
Page
web servicesCodeunit
web servicesQuery
web services
To use NAV web services, a client must be properly authenticated on NAV. After a successful authentication, it can read and write data using SOAP over the HTTP protocol.
Page web services
A NAV page published as a web service permits you to have CRUD operations (Create, Read, Update, Delete) on the entity linked to the Page
object.
When you expose a page as an OData web service, you can query that data to return a service metadata Entity Data Model Extension (EDMX) document, an AtomPub document, or a JavaScript Object Notation (JSON) document. If the exposed page has write permissions, you can also insert data on NAV.
In a page web service, each operation is executed on a single transaction with optimistic concurrency. These are the functions exposed on a page web service by default:
The term entity
used in operation signatures describes the data type that is used (the NAV table linked to the Page
object).
Codeunit web services
NAV codeunits can be exposed only as SOAP web services. When a codeunit
is exposed as a web service, all functions defined in the codeunit
web service and marked as Local = No
are exposed as operations to the client application.
To target a function defined in a codeunit
as public
, navigate to Functions | Properties and select Local = No
:
Query web services
A NAV Query object can be exposed only as an OData web service.
Query
objects can return the desired maximum number of rows as a result and you can specify this number via the TopNumberOfRows
property in the NAV Query
object:
In the service tier configuration (CustomSettings.config
file), the ODataServicesPageMaxSize
setting contains the maximum number of entities returned per page of OData results. The default value is 1000
but often you need to change this value in order to retrieve the correct result set. It's extremely important that you check this value or you may not have a correct result set returned.
When exposing Microsoft Dynamics NAV objects as web services, a developer has to decide which type of web service is better suited to their needs. Actually, the NAV platform offers these limitations:
- It is not currently possible to access Microsoft Dynamics NAV
Query
objects with SOAP web services - It is not currently possible to access
codeunits
with OData web services
The following table summarizes the types of web service applications that you can create with NAV:
Using filter expressions in an OData URI
When using an OData URI (for example by calling a Query
object exposed as a web service), you can use filter expressions directly in the URL.
To add a filter to an OData URI, add $filter=
at the end of the name of the published web service.
For example, the following URI filters the City
field in the Customer page to return all customers who are located in Milan
:
http://localhost:7048/DynamicsNAV/OData/Company('CRONUS International Ltd.')/Customer?$filter=City eq 'Milan'
You must use the appropriate notation for the different data types you use in a filter expression:
- String values must be delimited by single quotation marks
- Numeric values require no delimiters
DateTime
values must be delimited by single quotation marks and preceded by the worddatetime
, such asdatetime'2016-06-10T23:59:30.1432453Z'
The following table shows the most used filters that are supported in Microsoft Dynamics NAV OData web services and the equivalent C/AL filter expressions. Samples come from the publication of Page 21
(Customer Card
, Customer
as the service name) and Page 20
(General Ledger Entry, GLEntry as the service name), as explained on the MSDN site:
NAV web services configuration
When you install the Microsoft Dynamics NAV server, you can provide configuration information for web services directly in the setup phase or after that via the Microsoft Dynamics NAV Server Administration
tool application.
All these settings can also be manually managed by editing the CustomSettings.config
file on the server (this file is located by default in the C:Program FilesMicrosoft Dynamics NAV<versionNumber>Service
folder), where <versionNumber>
is the number that corresponds to the NAV version (for example 90 for NAV 2016).
If you open the Microsoft Dynamics NAV Server Administration tool and connect to your server instance, you can find these two settings tabs:
SOAP Services tab settings
Take a look at the fields in the SOAP Services tab in the Microsoft Dynamics NAV Server Administration tool in the following screenshot:
The following table depicts the fields in the SOAP Services tab as shown in the preceding screenshot:
Note
The maximum permitted size of an OData web service request is specified by the Max Message Size option in the SOAP Services tab as previously described.
OData Services tab settings
The following table describes the fields on the OData Services tab in the Microsoft Dynamics NAV Server Administration tool: