|
|
|
|
|
- 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.
 10 min 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. 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 - Go to the WINDEV home page (Ctrl + <).
- On the home page, click "Tutorial", then in "Tutorial - Consuming a web service", click "Open exercise project".
To import a web service into the project: - On the "Project" tab, in the "Project" group, expand "Import" and select "A web service". The import wizard starts. Go to the next step.
- Specify the address into which the web service WSDL description must be imported:
https://examples.webdev.info/WSTUTORIALV2_WEB/awws/WSTutorialV2.awws?wsdl Reminder: this web service is used to query a supplier database to check the availability (stock) of a product using its reference.
- Go to the next step. The web service is imported.
- Validate the information window. The imported web service is in the "Imported web services" folder of the "Project explorer" pane.
- 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: 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:
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: - Open the "WIN_Menu" window in the editor (double-click its name in the "Project explorer" pane, for example).
- On the "List of products" tab, add a Button control:
- On the "Creation" tab, in the "Usual controls" group, click
. - Click below the "Modify " Button control in the window.
- The control is automatically created.
- Change the characteristics of the Button control (select "Description" in the context menu):
- Name this control "BTN_InStock".
- Enter the caption "In stock?".
- Validate.
- Open the events associated with the control (select "Code" in the context menu).
- Write the following WLanguage code in the "Click BTN_InStock" event:
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.
- Close the code editor and save the window (
or Ctrl + S).
We will test the web service: - Test the project (click
in the quick access buttons). - Click the "List of products" tab if necessary.
- Select any product in the Table control and click "In stock?".
- Validate the information window and close the application.
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:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|