- Operating mode
- Special case: Using an intermediate WebService
In french: DéclareContexteWebservice
Allows you to declare a list of variables whose value will be persistent between the successive calls to a Webservice. This function indicates the variables that will be saved and restored during each call to the webservice. This gives you the ability to manage a context in the webservice.
DeclareWebserviceContext is taken into account when running the Webservices deployed on the WEBDEV Application Server (Webservice in .AWWS).
It is recommended to use this function in the "Initializing" event of the project (for project variables) and/or in the initialization code of classes or sets of procedures. In most cases, this function must be used in the process where the variables are declared and initialized.
If your project uses pre-launched sessions, this function must not be used in the project initialization event. This function must be used in the "Initializing the project after connection to the site" event.
- This function is intended to the developers with a good knowledge of WINDEV/WEBDEV.
- By default, a REST Webservice does not have a context. Therefore, this function cannot be used in a REST Webservice.
// -- Project "Initializing" event
gnNumCurrentProduct is int = 1
// Indicate that the value of gnNumCurrentProduct must be saved
// whenever the Webservice is called
// During the next calls to the Webservice:
// - either the value of gnNumCurrentProduct is not retrieved
// and it is automatically reinitialized with "1"
// (for example, during the first call by a new client)
// - or the value of gnNumCurrentProduct is retrieved and used
// (for example, during successive calls by the same client)
<Result> = DeclareWebserviceContext(<Name of variable 1> [, <Name of variable 2> [... [, <Name of variable N>]]])
- True if the specified variables have been restored,
- False otherwise (during the first call to the Webservice for example).
<Name of variable 1>: Type of variable
Name of the first variable that will be saved at the end of the display. The value of this variable will be retrieved during the successive calls to the Webservice.
<Name of variable 2>: Type of variable
Name of the second variable that will be saved at the end of the display. The value of this variable will be retrieved during the successive calls to the Webservice.
<Name of variable N>: Type of variable
Name of Nth variable that will be saved at the end of display. The value of this variable will be retrieved during the successive calls to the Webservice.
- The context is always saved on disk and transmitted via a SOAP header.
- DeclareWebserviceContext uses contexts on disk. The values of variables are always restored.
- The total size of values for the different variables is not limited.
- DeclareWebserviceContext can be used for 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 when a Webservice is called 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.
- Are not supported: the fixed arrays, the global members of classes, the associative arrays of local structures and the advanced types of WLanguage (like the Connection variables for example).
Special case: Using an intermediate WebService
In some cases, you may have to use an intermediate Webservice to use the variables.
Let's study the following case:
- A "WS1" Webservice uses DeclareWebserviceContext for a global variable named "globalString". This Webservice contains 2 functions:
- "Write(param)" that assigns "param" in "globalString"
- "Read()" that returns the content of "globalString".
- A client executable, consuming WS1, calls "WS1.Write("Hello")", then "WS1.Read()" retrieves the string sent.
- An intermediate Webservice "WS2", consuming WS1, contains 2 functions:
- "Write(param)" that calls "WS1.Write()".
- "Read()" that calls "WS1.Read()".
- A client executable, consuming WS2, calls "WS2.Write("Hello")", then "WS2.Read()" DOES NOT retrieve the string sent.
Solution: In the WS2 Webservice, use a "WriteRead()" function that runs "WS1.Write()" and "WS1.Read()" in the same process.
This page is also available for…