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

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