Tech Articles


ALTERNATIVA PARA CONSUMIR WEB SERVICES REST JSON VERSIONES ANTERIORES (6.5, … , 11.5)


Con los nuevos sistemas una de las cosas que hoy en día escuchamos es: tenemos un web services donde puedes consultar…

Por lo que ante esta necesidad y teniendo un sistema desarrollado originalmente en powerbuilder 6.5 ( les traigo esta solución.

Un “consumer” de WS REST

Para hacer este ejemplo utilizaremos objetos no visuales, principalmente el objeto internetresult.

1.-  Creamos un objeto heredado de internetresult (Estandard Class) al cual llamaremos: nvo_internet_result.

2.- Declaramos la siguiente variable de instancia

window  lw_child //Handle

 

3.- Agregamos una función la cual llamaremos of_set_window en el objeto  nvo internet_result.

  • Recibe argumento de tipo Window (Handle)

  • Retorna un Entero

4.- Agregamos código a una función la cual debe llamarse internetdata

  • Recibe argumento de tipo blob

  • Retorna un Entero

5.-  Creamos un objeto no visual custom (Custom Class) al cual llamaremos: nvo_cws

6.- Declaramos las siguientes variables de instancia

string is_authorization

string is_endpoint

Inet  iinet_base

nvo_internet_result iir_msgbox  // El objeto creado anteriormente

string is_request

window iw_window   //Handle

 

7.- Agregamos una función la cual llamaremos of_set_endpoint.

  • Recibe argumento de tipo String

  • Retorna un Entero

8.- Agregamos una función la cual llamaremos of_set_window en el objeto cws.

  • Recibe argumento de tipo Window (Handle)

  • Retorna un Entero

 

9.- Agregamos una función la cual llamaremos of_exec en el objeto nvo_cws.

 

10.- Una vez realizadas las acciones anteriores procedemos a crear la interface gráfica.

  1. Agregamos un objeto window a nuestra aplicación con los siguientes objetos:

    1. Single line edit al cual llamaremos: sle_resource, ahí pondremos donde esta nuestro recurso.

    2. Multiline edit al cual llamaremos: mle_1

    3. CommmandButton al cual llamaremos: cb_test

    4. Y finalmente un datawindowsal cual llamaremos: dw_ws, su dataobject será un datawindow tipo external con dos campos tipo string

11.- Procedemos a poner el código en nuestra window

Agregamos el siguiente código en el evento open

obj_cws = CREATE nvo_cws

12.- Agregamos la función of_respuesta  la cual es llamada dinámicamente .

13.- Finalmente ponemos el siguiente código en el evento clicked del botón

 

Imágenes de apoyo

Aunque nuestro web service rest puede producir  json y xml por default genera el json

 

 

GlassFish 5 con el 4.1.1 generaba diversas excepciones

 

Definición del datawindow external

Comments (2)
Monday, Jun 04 2018

where it comesthe object  lib_json.

I get an error trying to create the visual interfase:

Error C0001 Illegal data type: lib_json

Undefined variable: json

Please help where I should do corrections to the example code 

 

#5
0

Monday, Jun 04 2018

Hi,

You can comment this lines
//lib_Json...
//json..

With this you should retrieve since Web service

The lines commented above is for parse, and show in datawindow

#6
0

Find Articles by Tag

32-bit External Functions Class Variable HTTPClient Charts Installation WinAPI Validation Automated Testing Array JSONGenerator Stored Procedure DataType SQL Server Event Handling SDK Expression Interface InfoMaker PBDOM OAuth 2.0 PostgreSQL ODBC driver COM PDFlib Import Open Source Import JSON .NET DataStore REST OAuth SVN PFC Authentication Service Database Connection PowerServer Mobile DLL TreeView XML Application Repository Messagging Trial SnapDevelop DevOps RESTClient 64-bit Performance Model CI/CD IDE Platform Bug Encoding Debugger SnapObjects Export DataWindow Sort iOS UI Modernization Linux OS JSONParser Source Control License Database SOAP Deployment Jenkins Database Object Design Testing PowerBuilder Compiler SqlExecutor TortoiseGit Window Data UI Themes PostgreSQL PowerBuilder (Appeon) Authorization BLOB Web Service Proxy Encryption Export JSON Icon Database Table Schema SQL Event Handler Error ActiveX Elevate Conference CrypterObject Database Table Data DragDrop Database Table ODBC .NET Std Framework Migration Debugging OLE PowerServer Web Windows 10 Icons OrcaScript Resize Menu MessageBox CoderObject NativePDF Excel Script Text File Syntax Debug Source Code Database Profile Oracle PowerScript (PS) RichTextEdit Control RibbonBar Filter WebBrowser SqlModelMapper Android Database Painter PDF .NET Assembly Graph Azure Outlook DataWindow JSON Windows OS Web API Mobile Transaction API UI RibbonBar Builder JSON GhostScript Git Configuration TLS/SSL C# Branch & Merge PowerBuilder Event TFS