PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
New WINDEV Mobile 26 feature!
  • In this lesson you will learn the following concepts
  • Overview
  • Practical example
  • Importing a Webservice
  • Consuming a Webservice
  • Consuming a REST Webservice
Lesson 4.7. Consuming a Webservice
In this lesson you will learn the following concepts
  • Overview.
  • Importing and consuming a Webservice.
  • Consuming a REST Webservice.
Lesson duration

Estimated time: 10 mn
Previous LessonTable of contentsNext Lesson
Overview
In most cases, a Web service is defined as an application that can be accessed via standard Internet protocols. More specifically, Web services allow several computers connected via Internet to interact.
Web services allow you to run procedures and processes on a remote Web server (.NET, SOAP or J2EE) from a client computer.
With WINDEV Mobile, these Web services can be used as client, via the SOAP protocol on HTTP (the standard Internet protocol for transferring HTML pages) and with the SOAPxx, DotNetxx and J2EExx functions.
Regardless of the Web server platform (.NET, J2EE, etc.), a Web service can be accessed via the SOAP protocol.

Note

With WINDEV Mobile, you don't have to be an expert in this field.
A wizard takes care of ("almost") everything!

Practical example

A Webservice specific to this tutorial allows you to check the different operations that can be performed on a Webservice.
When integrated to the "WM Product Management" project, this Webservice is used to query a supplier database to check whether a product is available in stock using its reference.
First, we will import the Webservice into the "WM Product Management" project, and then use it in the application to check the product availability via a Product form.
  • To follow this lesson, open (if necessary) the "WM Product Management" project you worked on in the previous lesson.
    1. Go to the WINDEV Mobile home page (Ctrl + <).
    2. On the home page, click "Tutorial", then in "Part 4 - Development of an Android/iOS" application", double-click "Android/iOS product management (Exercise)".
    3. A dialogue box prompts you to open the project you worked on in the previous lesson. You can open the local copy or the original project. Select "Open the local copy".

      Answers

      A corrected project is available. This project contains the different windows created in this lesson. To open the corrected project, go to the home page and click "Tutorial", then in "Part 4 - Development of an Android/iOS application", double-click "Android/iOS product management (Answers)".
Importing a Webservice
  • To import a Webservice into the project:
    1. On the "Project" pane, in the "Project" group, expand "Import" and select "A Web service".
    2. The import wizard starts. Go to the next step.
    3. Specify the address into which the WSDL description of the Webservice must be imported:
      https://examples.webdev.info/WSTUTORIALV2_WEB/awws/WSTutorialV2.awws?wsdl

      Reminder: This Webservice is used to query a supplier database to check the availability (stock) of a product using its reference.
      Webservice import wizard
    4. Go to the next step. The Webservice is imported.
      Import completed
    5. Validate the information window. The imported Webservice is in the "Imported Webservices" folder of the "Project explorer" pane.
    6. In the "Project explorer" pane, expand the "Imported Webservices" folder.
Let's take a closer look at the information displayed in the "Project explorer" pane:
'Project explorer' pane
The structure includes:
  • the Webservice name (WSTutorialV2 in this example),
  • the name of each function (ProductInStock in this example).
To see the Webservice 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 Webservice
In our example "WM Product Management", we will integrate the Webservice call in the internal window that displays the product details. We will create a "Stock" button to check the availability of the product via the Webservice.
  • To use the Webservice:
    1. Open the "IW_Product" internal window in the editor (double-click on it in the "Project explorer" pane).
    2. Reduce the width of the "Reorder" control.
    3. Delete the "Quantity" control.
    4. Add a Button control:
      • On the "Creation" pane, in the "Usual controls" group, click Create a Button control.
      • Click in the window next to the "Reorder." control.
      • The control is automatically created.
    5. Modify the characteristics of the control (select "Description" in the context menu). Enter "BTN_Stock" in the "Name" field and "Stock" in the "Caption" field.
      Position of the 'Stock' button
    6. Open the events associated with the control (select "Code" in the context menu).
    7. Write the following WLanguage code in the "Click BTN_Stock" event:
      // Display SOAP Webservice response
      InfoBuild("Number of ""%1"" products in stock: %2", EDT_Reference, ...
      ProductInStock(EDT_Reference))
      Let's analyze this code:
      • The ProductInStock function of the Webservice is called. This code uses the function prototype that was displayed beforehand in the code editor.
      • The response is formatted and displayed.
    8. Close the code editor and save the window ( Save window or Ctrl + S).
    9. Close the "IW_Product" internal window.
  • We will test the Webservice:
    1. Open the WIN_Advanced_LIST_Products window (e.g., press CTRL + E).
    2. Test the window (click Test window in the quick access buttons).
    3. Double-click a product: the product form appears.
    4. Click "Stock".
      Webservice test
    5. Validate the information window and close the simulator.
Consuming a REST Webservice
In our example, we consumed a SOAP Webservice. Now we will consume a REST Webservice. In this case, you don't need to import the Webservice into the application. Simply call the desired Webservice procedure.
In our example, we deployed a REST Webservice that performs the same process as the SOAP Webservice used previously. This REST Webservice can be used to get the stock information of the specified product using the following address:
https://examples.webdev.info/product/<Product reference>


  • Let's see how to use this REST Webservice in our example.
    1. Go back to the editor and open the code of the BTN_Stock control.
    2. Comment out the existing code (select the lines of code and press Ctrl + //).
    3. Type the following code:
      // Display REST Webservice response
      h is httpRequest
      h.Method = httpGet
      h.URL = "https://examples.webdev.info/product/" + EDT_Reference
      h.ContentType = "application/json"
       
      r is restResponse = RESTSend(h)
      sContent is ANSI string
       
      IF r.StatusCode = 200 THEN // Request successfully completed
      sContent = r.Content
      Info(sContent)
      ELSE
      Info("An error has occurred " +  ErrorInfo() + r.StatusCode + r.DescriptionStatusCode)
      END
      This code is used to:
      • Declare an httpRequest variable. This variable defines the parameters of the query sent to the REST Webservice. The properties of this variable are:
        • The method used: GET in this case.
        • The Webservice call URL: it is the URL that we presented previously. In our case, the product reference corresponds to the value in the EDT_Reference control.
        • The type of content of the HTTP message that will be sent to the server. In this case, the message is in JSON format.
      • Send the request to the server and get the response using RESTSend. The response is a restResponse variable.
      • Format the response.
    4. Close the code editor and save the window ( Save window or Ctrl + S).
  • We will test the Webservice:
    1. If necessary, open the WIN_Advanced_LIST_Products window (e.g., press CTRL + E).
    2. Test the window (click Test window in the quick access buttons).
    3. Double-click a product: the product form appears.
    4. Click "Stock".
    5. Validate the information window and close the simulator.
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 26
This page is also available for…
Comments
Click [Add] to post a comment