J
Joseph Betts
Guest
Hello Progress4GL Developers,
I am trying to use progress to consume a SOAP API. At the moment, I am just using a opensource sample SOAP service called: http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL.
The following program works a dream (i.e user inputs country code such as "ESP" and details about Spain are showed to user). The result is stored in temp-table1 and temp-table2:
/******* Sample Application to show Progress4GL Consuming a SOAP API *************/
/******* VARIABLES ***************************************************************/
DEFINE VARIABLE lReturn AS LOGICAL NO-UNDO.
DEFINE VARIABLE hServer AS HANDLE NO-UNDO.
DEFINE VARIABLE hPortType AS HANDLE NO-UNDO.
DEFINE VARIABLE capitalCity as LONGCHAR NO-UNDO.
DEFINE VARIABLE iCntryCode as char no-undo label "Country Code".
DEFINE VARIABLE oResponse as LONGCHAR no-undo.
/******* CONNECTION SETTINGS TO SOAP SERVICE *************************************/
CREATE SERVER hServer.
lReturn = hServer:CONNECT("-WSDL http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL").
IF lReturn = NO THEN DO:
MESSAGE
"Could not connect to WebService server".
END.
/******* SETTING PORT TYPE *******************************************************/
RUN CountryInfoServiceSoapType SET hPortType ON SERVER hServer.
IF NOT VALID-HANDLE(hPortType) THEN DO:
MESSAGE
"Could not establish portType".
END.
/****** USER UPDATE FORM**********************************************************/
UPDATE iCntryCode.
/****** NAME OF DATA FUNCTION TO RUN *********************************************/
RUN FullCountryInfo IN hPortType (INPUT iCntryCode, OUTPUT oResponse) NO-ERROR.
/****** TEMP TABLE TO HOLD ALL CAPITAL CITY FIELDS *******************************/
DEFINE TEMP-TABLE temptable1
SERIALIZE-NAME "sCapitalCity"
FIELD capitalCity AS CHAR XML-NODE-TYPE "text".
/****** DATASET WHICH RUNS CONVERSION ********************************************/
DEFINE DATASET dsa SERIALIZE-NAME "FullCountryInfoResult" FOR temptable1.
/***** TEMP TABLE TO HOLD ALL CURRENCY FIELDS ************************************/
DEFINE TEMP-TABLE temptable2
SERIALIZE-NAME "sCurrencyISOCode"
FIELD currencyCode AS CHAR XML-NODE-TYPE "text".
/****** DATASET WHICH RUNS CONVERSION ********************************************/
DEFINE DATASET dsb SERIALIZE-NAME "FullCountryInfoResult" FOR temptable2.
/****** POPULATE DATASET AND TEMP-TABLES FROM SOAP RESPONSE **********************/
DATASET dsa:READ-XML( "longchar", oResponse, ?, ?, ? ).
DATASET dsb:READ-XML( "longchar", oResponse, ?, ?, ? ).
FOR EACH temptable1 no-lock, each temptable2 no-lock:
DISPLAY temptable1.capitalcity temptable2.currencyCode.
END.
PAUSE 100.
/****** STOP CONNECTION TO SERVER ************************************************/
DELETE PROCEDURE hPortType.
hServerISCONNECT().
DELETE OBJECT hServer.
However, this sample web-service also has a procedure called FullCountryInfoAllCountries. This will give response for all countries. I have tried to re-factor the code above so that all temp-table1 and temp-table2 will be populated with all countries however I am having difficulty parsing the XML data.
I have tried experimenting with the NAMESPACE-URI, SERIALIZATION-NAME, and XML-NODE-NAME statements, but can't get it to work. The problem I have is that the XML response from FullCountryInfoAllCountries is structured differently to FullCountryInfo, and I always recieve an error along the lines of 'Namespace not found', or it will return nothing in the temp-tables.
Many Thanks in Advance!
Continue reading...
I am trying to use progress to consume a SOAP API. At the moment, I am just using a opensource sample SOAP service called: http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL.
The following program works a dream (i.e user inputs country code such as "ESP" and details about Spain are showed to user). The result is stored in temp-table1 and temp-table2:
/******* Sample Application to show Progress4GL Consuming a SOAP API *************/
/******* VARIABLES ***************************************************************/
DEFINE VARIABLE lReturn AS LOGICAL NO-UNDO.
DEFINE VARIABLE hServer AS HANDLE NO-UNDO.
DEFINE VARIABLE hPortType AS HANDLE NO-UNDO.
DEFINE VARIABLE capitalCity as LONGCHAR NO-UNDO.
DEFINE VARIABLE iCntryCode as char no-undo label "Country Code".
DEFINE VARIABLE oResponse as LONGCHAR no-undo.
/******* CONNECTION SETTINGS TO SOAP SERVICE *************************************/
CREATE SERVER hServer.
lReturn = hServer:CONNECT("-WSDL http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?WSDL").
IF lReturn = NO THEN DO:
MESSAGE
"Could not connect to WebService server".
END.
/******* SETTING PORT TYPE *******************************************************/
RUN CountryInfoServiceSoapType SET hPortType ON SERVER hServer.
IF NOT VALID-HANDLE(hPortType) THEN DO:
MESSAGE
"Could not establish portType".
END.
/****** USER UPDATE FORM**********************************************************/
UPDATE iCntryCode.
/****** NAME OF DATA FUNCTION TO RUN *********************************************/
RUN FullCountryInfo IN hPortType (INPUT iCntryCode, OUTPUT oResponse) NO-ERROR.
/****** TEMP TABLE TO HOLD ALL CAPITAL CITY FIELDS *******************************/
DEFINE TEMP-TABLE temptable1
SERIALIZE-NAME "sCapitalCity"
FIELD capitalCity AS CHAR XML-NODE-TYPE "text".
/****** DATASET WHICH RUNS CONVERSION ********************************************/
DEFINE DATASET dsa SERIALIZE-NAME "FullCountryInfoResult" FOR temptable1.
/***** TEMP TABLE TO HOLD ALL CURRENCY FIELDS ************************************/
DEFINE TEMP-TABLE temptable2
SERIALIZE-NAME "sCurrencyISOCode"
FIELD currencyCode AS CHAR XML-NODE-TYPE "text".
/****** DATASET WHICH RUNS CONVERSION ********************************************/
DEFINE DATASET dsb SERIALIZE-NAME "FullCountryInfoResult" FOR temptable2.
/****** POPULATE DATASET AND TEMP-TABLES FROM SOAP RESPONSE **********************/
DATASET dsa:READ-XML( "longchar", oResponse, ?, ?, ? ).
DATASET dsb:READ-XML( "longchar", oResponse, ?, ?, ? ).
FOR EACH temptable1 no-lock, each temptable2 no-lock:
DISPLAY temptable1.capitalcity temptable2.currencyCode.
END.
PAUSE 100.
/****** STOP CONNECTION TO SERVER ************************************************/
DELETE PROCEDURE hPortType.
hServerISCONNECT().
DELETE OBJECT hServer.
However, this sample web-service also has a procedure called FullCountryInfoAllCountries. This will give response for all countries. I have tried to re-factor the code above so that all temp-table1 and temp-table2 will be populated with all countries however I am having difficulty parsing the XML data.
I have tried experimenting with the NAMESPACE-URI, SERIALIZATION-NAME, and XML-NODE-NAME statements, but can't get it to work. The problem I have is that the XML response from FullCountryInfoAllCountries is structured differently to FullCountryInfo, and I always recieve an error along the lines of 'Namespace not found', or it will return nothing in the temp-tables.
Many Thanks in Advance!
Continue reading...