Whether you expose or consume Web services, exceptions and dialogs that appear during execution of the code must be handled properly. Exceptions must be handled to prevent the system from ending the Web service execution. There are two ways of handling exceptions—by writing conditional code inside Microsoft Dynamics NAV, or by writing the code where the Web service is called. The best solutions use both methods for safety.

When Exposing Web Services

The developer who exposes a Web service must consider issues that may arise. Specifically, the developer should be sure that the code doesn't require any interaction with a user. The primary way of suppressing UI is the implementation of a GUIALLOWED statement that checks, for example, if a codeunit is called from Microsoft Dynamics NAV or from a Web service. You do not want to throw any errors if a codeunit is called from a Web service.

When implementing a conditional code check inside Microsoft Dynamics NAV, implement the check only around code that could cause an error. Do not encapsulate the whole business logic in this check.


The server returns the following exception when trying to invoke a dialog UI through a Web service: Microsoft.Dynamics.Nav.Types.Exceptions.NavNCLCallbackNotAllowedException: Callback functions are not allowed.

DIALOG Function

The DIALOG function in C/AL is for storing dialog windows. Any code that uses this function must be considered when working with Web services. The following table lists the methods and their behavior when called from a Web service.

Behavior when called from a Web service Method name

Is accepted and doesn't cause an exception.


Throws an exception.










When Consuming Web Services

Remember also to handle exceptions in code that calls a Web service. When implementing a code check outside of Microsoft Dynamics NAV, appropriate exception capturing code should be included around any call to a Microsoft Dynamics NAV Web service.

See Also