A type of problem that programmers encounter is a program that compiles, but then behaves differently than expected.
Debugging is the act of observing the run-time behavior of a program and determining the location of semantic errors. With the debugger, you can break (suspend) execution of your program to examine your code, evaluate and edit variables in your program, view data in database tables and control the execution of the instructions in your source code.
You can debug your Web Service function code in several different ways:
Debug the code using the Debugger.
Use the Web Service function's test page to call the Web Service function and examine the result.
Build a Web Service client
and debug the Web Service from the client side. If you build a Windows
client, you can use the Web Service Helper view to see the XML code
sent to and returned from the Web Service.
You will learn about building Web Service clients in Consuming
Your First Web Service.
This section assumes that you have been going through the Quick Start tutorial step by step.
If you skipped the Windows application part of Quick Start, you should read the Handling Compiler Errors section now and return to this page when you have completed it.
You are going to make a change in the code of your Greeting Web Service function, to cause it to behave differently than you want it to behave. Then, you will learn how to use the debugger to track down and solve the problem.
Bring up the code for the Greeting function in the Greeting.wo file in Code Explorer.
Change the line
Move "Hello, " to sHello
to
Move "Hello," to sHello
(remove the space following the comma in 'Hello,')
Click on the Run button on the Studio's toolbar. The program will compile and run.
When the application runs,
your browser should display the http://localhost/GreetingWebService/GreetingService.wso
page. Click the Greeting Web Service
link to load the GreetingService.wso page. On this page, click on
the Greeting link. Type your
name into the sName form and
click the Invoke button.
You will see that the result that appears in the Result form now is,
for example, "Hello,John, how are you today?", with the
space between the comma and the name missing. You will now use the
debugger to track down why the space is missing.
Leave the program running and switch back to the Studio. Click in the left hand margin of the code editor next to the code line
move "Hello," to sHello

This will place a red dot in the left margin, indicating that you have just placed a breakpoint on this line of code.
Debuggers work by causing executing programs to stop and examining the program at this "frozen" time. Breakpoints on lines of code cause the debugger to halt the program when reaching that line of code, just prior to executing it.
Now
you will execute the program up to this line of code to have the debugger
stop at this point. Since the breakpoint is in the Greeting function
of the oGreeting WSO, you need to run your program and click on the
Invoke button to get the debugger to execute the program's code up
to this breakpoint.
Return to the running program and click on the Invoke
button again.
This time, the program is stopped by the debugger at the breakpoint.
If
you place your mouse cursor over any local variable in Function Greeting,
you will see the current value of the variable pop up as a tool tip.
Of course, at this point in the code, all variables should show up
to be blank.

Notice also the green arrow
in the left margin, which currently overlaps the red dot for the breakpoint
you placed. The green arrow indicates the line on which the program
is currently "frozen". This is the next line that will execute
in the program.
Take
a look at the Locals window. If the Locals window is not open, click
on the Locals icon on the
Studio's toolbar.

This will open the Locals window, which lists all local variables and
their current values. This is a useful window to keep open when debugging,
since it reflects the values of all local variables as you step through
the code.
Click
on the Step Over button on
the Studio's toolbar (or press F10).

Stepping through code is an important debugging concept. A step causes the debugger to tell the program being debugged to execute lines of code as you tell it to.
The debugger has executed the line
move "Hello," to sHello
Notice that the variable sHello now contains "Hello,". You can see this in the Locals window and also by holding the mouse cursor over the variable sName anywhere inside Function HelloWorld.
Click on the Step Over toolbar button twice. The green arrow should now be next to the line
Function_Return sReply

The variable sHello now contains "Hello," sName contains the
name you typed into the Name form, sHowAreYou contains ", how are
you today?" and sReply contains the concatenated result of sHello
+ sName + sHowAreYou ("Hello,Dennis, how are you today" in our
example images).
It is now readily apparent that the reason for the missing space is that
there was no space placed either at the end of sHello or the beginning
of sName.
You will notice that the value of sReply is displayed in red in the Locals window (yellow if running the Studio in Dark Mode). This is a visual cue to indicate that the value of sReply has just changed.
Take
a look at the Watches window. If the Watches window is not open, click
on the Watches icon on the
Studio's toolbar.

This will open the Watches window, another useful window to keep open
when debugging. The Watches window can display any expression you
wish to evaluate while debugging. Try it like this:
Double-click
on sReply in the code editor
(this selects the entire word). Drag and drop it into the Name
column of the Watches window.
You will see that the Value column displays the current value of sReply,
which is "Hello,Dennis, how are you today" in our current
sample.
Highlight
the expression sHello + sName + sHowAreYou
in the code editor. Drag and drop it into the Name
column of the Watches window.
You will see that the Value column displays the current value of (sHello
+ sName + sHowAreYouToday), which is "Hello,Dennis, how are you
today" in our current sample (just like sReply).

Click
in the Name column of the Watches
window of the row which currently contains sHello
+ sName + sHowAreYou. This will highlight the entire current
row. If you click in the Name
column once more, you will see that it is now editable.
Change the expression to sHello +
" " + sName + sHowAreYou and press Enter.
You will see that the Value column now displays the current value of
(sHello + " " + sName + sHowAreYou), which is "Hello,
Dennis, how are you today?" in our current sample.

It is now readily apparent that the reason for the missing space is
that there was no space placed either at the end of sHello or the
beginning of sName.
Be sure to change "Hello," back to "Hello, ". You will call the Greeting web service function in the Consuming Your First Web Service tutorial.
We encourage you to spend some time using
the DataFlex Debugger, it is a very powerful tool and the features we
have shown you here barely scratch the surface of what you can do with
it.
Mastering the Debugger will help you understand how DataFlex works and
make you a better programmer.
You have just learned how to create a web service application and a web service function in the DataFlex Studio, and how to compile and debug them. Next, you will learn how to use web services in DataFlex applications: Consuming Your First Web Service