New WINDEV 2024 feature!
Help / WINDEV Tutorial / Tutorial - Consuming a web service
  • What is a web service?
  • Practical example
  • Importing a web service
  • Consuming a web service
  • To sum up

Tutorial - Consuming a web service

We will cover the following topics:
  • What is a web service?
  • Practical example:
    • Importing a web service.
    • Consuming a web service.
Durée de la leçon 10 min
What is a web service?
First of all, let's look at what a web service is. Here's a simple definition.
A web service is a set of entry points made available to users to complete various processes. For example, a remote access service provides the processes used to access the data. Data exchange with a web service is done in XML format, via SOAP (Simple Object Access Protocol) and HTTP.
Based on the WSDL (Web Services Description Language) description of this service, WINDEV will automatically generate WLanguage types and functions corresponding to the web service programming interface.
To use the web service, simply use the functions generated during the import.
Practical example
A web service specific to this tutorial allows you to try the different operations that can be performed on a web service.
When integrated to the "WD Full Application" project, this web service is used to query a supplier database to check whether a product is available in stock using its reference.
First, we will import the web service into the "WD Full Application" project, then use it in the application to check the availability of the product from a product details window.
Opening the example project
  1. Go to the WINDEV home page (Ctrl + <).
  2. On the home page, click "Tutorial", then in "Tutorial - WINDEV Application: Manage data", double-click "Full application - Answers".
  3. If necessary, select the "Windows 64-bit executable" project configuration: in the "Project explorer" pane, in the "Configurations" folder, double-click "Windows 64-bit executable".
Importing a web service
To import a web service into the project:
  1. On the "Project" tab, in the "Project" group, expand "Import" and select "A web service". The import wizard starts. Go to the next step.
  2. Specify the address into which the web service WSDL description must be imported:

    Reminder: This web service is used to query a supplier database to check the availability (stock) of a product using its reference.
    Web service import wizard
  3. Go to the next step. The web service is imported.
    Import completed
  4. Validate the information window. The imported web service is in the "Imported web services" folder of the "Project explorer" pane.
  5. In the "Project explorer" pane, expand the "Imported web services" folder.
Let's take a closer look at the information displayed in the "Project explorer" pane:
'Project explorer' pane
The structure of the web service consists of:
  • the web service name (WSTutorialV2 in this example),
  • the name of each function (ProductInStock in this example).
To see the web service call syntax, double-click the name of the function in the "Project explorer" pane. The code editor displays the function description, with the prototype for calling the function:
Call to function
Consuming a web service
In our "WD Full Application" example, the call to the web service will be included in the tab used to view the list of products. We will create an "In stock?" button to check the availability of the product via the web service.
To use the web service in our project:
  1. Open the "WIN_Menu" window in the editor (double-click its name in the "Project explorer" pane, for example).
  2. In the "List of products" tab, add a Button control:
    • On the "Creation" tab, in the "Usual controls" group, click Create a Button control.
    • Click below the "Modify " Button control in the window.
    • The control is automatically created.
  3. Change the characteristics of the Button control (select "Description" in the context menu):
    • Name this control "BTN_InStock".
    • Enter the caption "In stock?".
      Position of the 'In stock?' Button control
  4. Validate.
  5. Open the events associated with the control (select "Code" in the context menu).
  6. Write the following WLanguage code in the "Click BTN_InStock" event:
    // Displays the web service response
    InfoBuild("Number of ""%1"" products in stock: %2", COL_Reference, ProductInStock(COL_Reference))
    Let's analyze this code:
    • The ProductInStock function of the web service is called. This code uses the function prototype that was displayed previously in the code editor.
    • The response is formatted and displayed.
  7. Close the code editor and save the window (Save window or Ctrl + S).
We will test the web service:
  1. Test the project (click Test project in the quick access buttons).
  2. Click the "List of products" tab if necessary.
  3. Select any product in the Table control and click "In stock?".
    Web service test
  4. Validate the information window and close the application.
To sum up
In this tutorial, we saw how to import and use / consume a web service in our application. To learn more, take a look at the following pages:
Table of contents
Minimum version required
  • Version 2024
Click [Add] to post a comment

Last update: 12/04/2023

Send a report | Local help