#06 DEBUG & ATTACH: HOW TO DEBUG WEB SERVICES AND JOB QUEUE

Skip to content

#06 DEBUG & ATTACH: HOW TO DEBUG WEB SERVICES AND JOB QUEUE

Finding and fixing bugs or errors is part of our daily tasks. This process may take a lot of time if we do not use the debugger and, even more, if the error occurs in a Web Service or in a Job Queue task.

In the older versions, the solution was to use the “Debug Next” functionality, but in Visual Studio Code that functionality is not present. No problem, we’ll use Attach.

 

1 Create a basic Web Service Codeunit
A new Codeunit was created with a method that returns a random color.

Create a basic Web Service Codeunit_image#0192 Publish the Codeunit as a Web Service in Business Central
After publishing, make sure you can access the SOAP URL.

Publish the Codeunit_#0193 In VS Code, add a new “attach” configuration in launch.json

In VS Code, add a new “attach” configuration in launch.json_image#0194 Set the Breakpoint in VS Code and start a Debug Session with “Debug without publishing (Ctrl + Shift + F5)” and select the “Attach: BC180” configuration
Set the Breakpoint in VS Code and start a Debug Session_image#0195 Use SOAP UI (or Postman) to call the Method

Use SOAP UI (or Postman) to call the Method_image#0196 The debugger will break on the Breakpoint

The debugger will break on the Breakpoint_image#019

Notes:

  1. The example above will also work with Job Queue if you change the “breakOnNext” property to “Background” in the attach configuration in launch.json.
  2. Notes_image#019 To attach the app must be firstly published without debugging, before you start the debugging session (A).
(A) https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-attach-debug-next