- How to make a Webservice available?
- Creating the Webservice
- Managing contexts
- Generating the Webservice
- Deploying a Webservice and running its test
- Deploying a Webservice
- Special case: Deploying a Webservice and running its test on the local computer
Creating, generating and deploying a Webservice
WINDEV and WEBDEV allow you to generate Webservices directly. Then, these Webservices can be used in the WINDEV, WEBDEV, WINDEV Mobile projects or in any other language.
A Webservice includes a set of functions WITHOUT interface. Indeed, this type of module being run on a server, there is no need to develop a user interface. Therefore, the webservice will include WLanguage functions organized in sets of procedures. These functions can handle a database (HFSQL, Oracle, AS/400, ...).
Caution: Deploying a WINDEV or WEBDEV Webservice requires the use of a WEBDEV Application Server. Via this distribution mode, the Webservices created with WINDEV/WEBDEV present several types of benefits:
- Webservices deployed on a WEBDEV Application Server (compatible with all the Web servers).
- Several modes for deploying the Webservice (physical media, FTP, Cloud).
- Heavy workload possible.
- Webservices that can operate on all the Windows versions (32 and 64 bits) as well as in Linux.
How to make a Webservice available?
To create a Webservice:
- Create a WINDEV or WEBDEV project whose type is Webservice or a Webservice configuration in an existing project.
- When creating a project, select "SOAP or REST webservice".
- To create a Webservice project configuration, go to the "Project" tab, "Project configuration" group, expand "New configuration" and select "Webservice".
- Create one or more sets of procedures:
- In the project explorer, select the "Procedures" folder.
- Select "New" from the popup menu..
- Create the global procedures or the functions corresponding to the processes that must be performed on the server.
// Procédure globale Addition
PROCÉDURE Addition(nNombre1 is int, nNombre2 is int)
nRésultat is int
nRésultat = nNombre1 + nNombre2
Each global procedure can be run by the WEBDEV Application Server.
Caution: The Webservice must have no GUI (no window, report, trace window or dialog box). It is also limited by the rights defined on the Web server ("Internet guest" account in Windows).
- If the parameters of the procedures have no type, they will be automatically received as Unicode character strings. Therefore, you must specify the type of the parameters that must be different from a Unicode character string.
- The procedures can be marked as public or private. A public procedure can be used in the projects that will import the Webservice. A private procedure cannot be used in the projects that will import the Webservice (the procedure will not be visible in the project explorer). To mark a procedure as public or private, use the popup menu on the name of the procedure in the project explorer.
- The procedures can return classes, structures, arrays of structures or arrays of classes. The returned arrays are limited to one dimension.
- Type (if necessary) the initialization code and the closing code of project. These two codes will be respectively run when loading and when unloading the library of the Webservice.
To keep the value of global variables during successive calls to a webservice, you have the ability to use a management of contexts. The management of contexts is performed on disk: the value of different variables is stored in a file on the server. A context identifier is used to retrieve the context stored during a next call to the webservice. This identifier is stored in a SOAP header on the client computer. This identifier guarantees the security of the data stored.
This operating mode is as follows:
- The identifier is stored in a SOAP header. When using DeclareWebserviceContext, the WSDL is modified and it indicates that the format accepts a header section with a precise name and a specific format.
- The client transmits this information.
- During the first call, the value is empty, the server creates a new session.
- If the value is missing, the server creates a new session.
- The server returns the requested information.
To implement a management of contexts:
- Use DeclareWebserviceContext to store the desired variables. We recommend that you use this function in the initialization code of project (for the project variables) and/or in the initialization code of sets of procedures or classes. In most cases, this function must be used in the process where the variables are declared and initialized.
- The context is always saved on disk and transmitted via a SOAP header.
- DeclareWebserviceContext uses the contexts on disk. The values of variables are always restored.
- The total size of values for the different variables is not limited.
- The DeclareWebserviceContext function can be used for the sensitive data (user password for example).
- If two variables are saved with the same name (one in the project and the other one in a page for example), the two variables are stored independently.
- DeclareWebserviceContext returns False if one of the variables was not restored.
- All the variables passed to DeclareWebserviceContext during a call to a webservice can be retrieved during the next call. The variables that were passed beforehand are automatically saved again.
- The simple variables (integer, string, ...) are supported as well as the structure, class, array or associative array variables. The fixed arrays, the global members of classes and the associative arrays of local structures are not supported.
- To delete a specific variable from the context, you have the ability to use CancelWebserviceContext.
Remark: The WEBDEV administrator gives you the ability to configure the duration regarding the validity of webservice contexts ("Duration of webservice contexts" in the "Configuration" tab). As soon as the specified duration is exceeded, and if no new request was performed, the context file is deleted.
Generating the Webservice
To generate a Webservice:
- Select (if necessary) the configuration corresponding to the Webservice in the project explorer.
- Generate the Webservice:
- On the "Project" tab, in the "Generation" group, click "Generate".
- Click the generation icon in the quick access buttons.
- The Webservice generation wizard starts.
- In the wizard, specify:
- the name of the Webservice. By default, the Webservice name corresponds to the name of the current project. It is possible to change the name of the Webservice (the project name will not be changed)..
- the mode for passing parameters to the functions.
Remark: We recommend that you use the direct setting of functions.
- Go to the next step.
- Select the elements that will be included in the Webservice. These elements correspond to anything but the interface elements (window, page, report, ...). Check the elements to include and the ones that will be called in the Webservice. You can:
- Add elements
Any type of file can be added to the list of elements inserted into the library: images, text files, etc.
- Delete elements
The corresponding files and their dependencies will be ignored in the library.
- Create the webservice from an existing description (*.WDU file)
When creating a WINDEV library, a ".WDU" file with the same name is automatically created. This file contains all the references of the elements included in the library.
- Go to the next step.
- Check the accessible elements. The accessible elements correspond to the procedures that contain functions visible by the client application that calls the Webservice.
Caution: If a set of procedures becomes accessible, all the global procedures belonging to this set will be accessible. Two methods can be used to hide some procedures:
- include these procedures in a specific set and do not make this set accessible.
- use the PRIVATE keyword to make the procedure inaccessible (syntax: PRIVATE PROCEDURE MyProc()). For more details, see Global procedures.
- End the wizard to generate the Webservice.
- The deployment wizard is automatically started thereafter.
Deploying a Webservice and running its test
Deploying a Webservice
In order to be used, a Webservice must be deployed on a WEBDEV Application Server.
Several deployment methods can be used:
- Deploying the Webservice on a remote WEBDEV application server.
- Deploying the Webservice in the CLOUD for PC SOFT applications.
- Deploying the Webservice via the test hosting service of PC SOFT.
- Creating a remote deployment package.
- Creating a setup by physical media.
- Deploying the Webservice on the local computer.
- Creating a Webservice docker image.
The options for deploying a Webservice are identical to the options for deploying a WEBDEV site. For more details, see Deploying a site
Special case: Deploying a Webservice and running its test on the local computer
The test of the created Webservice can be run on the developer computer. To do so, select "Deploy the Webservice on the local computer". This type of setup is available only if WEBDEV is available on the development computer. In this case, the application server used is the one of WEBDEV.
At the end of the setup, a screen appears showing 2 links:
Once the link was clicked or the address typed in your browser, an HTML page is displayed: this page contains the accesses to all the functions developed in the Webservice as well as a link to the WSDL. This page is automatically created when generating the Webservice as well as all the HTML pages used to run the test of each Webservice function.
- a link that indicates the address of the test page of the webservice (http://user-pc/MYWEBSERVICE_WEB/awws/index.htm)
- a link that indicates the address of WSDL (http://user-PC/MYWEBSERVICE_WEB/awws/MyWebservice.awws?wsdl)
In our example, you will find the access to the "Addition" function:
When you click a function to test it, a new HTML page is displayed: This page contains controls used to enter the parameters for calling the function being tested. In this case, simply fill out the controls and click "Test". A result page will be displayed in return.
In our example, two numbers must be passed to the "Addition" function:
The result page generated will be:
The result is in XML format. The return values are encapsulated in XML tags. In our example, the return value of the "Addition" functions is enclosed in the "AdditionResult" tag.
This page is also available for…