/*******************************************************************/
/* client_WeatherG.p */
/*******************************************************************/
DEFINE VARIABLE hWebService AS HANDLE    NO-UNDO.
DEFINE VARIABLE hPortType   AS HANDLE    NO-UNDO.
DEFINE VARIABLE cResponse   AS CHARACTER NO-UNDO.
DEFINE VARIABLE li          AS INTEGER   NO-UNDO.
DEFINE VARIABLE retValue    AS CHARACTER INITIAL "OK" NO-UNDO.
DEFINE VARIABLE err         AS LOGICAL   NO-UNDO.
DEFINE VARIABLE result      AS CHARACTER NO-UNDO.
DEFINE STREAM ls.
/*******************************************************************/
CREATE SERVER hWebService.
ETIME(true).
li = MTIME.

hWebService:CONNECT("-WSDL 'http://www.webservicex.net/globalweather.asmx?WSDL'
  -Service GlobalWeather
  -Port GlobalWeatherSoap").


IF NOT hWebService:CONNECTED() THEN DO:
    MESSAGE "SERVER NOT CONNECTED" VIEW-AS ALERT-BOX.
    retValue = "ERROR".
END.


RUN GlobalWeatherSoap SET hPortType ON SERVER hWebService NO-ERROR.

IF ERROR-STATUS:ERROR THEN DO:
    MESSAGE "Failed to create hPortType" VIEW-AS ALERT-BOX.
    retValue = "ERROR".
END.

DEFINE VARIABLE CountryName      AS CHARACTER NO-UNDO.
DEFINE VARIABLE GetWeatherResult AS CHARACTER NO-UNDO.
DEFINE VARIABLE CityName         AS CHARACTER NO-UNDO.
CountryName = "FRANCE".
CityName = "Paris-Aeroport Charles De Gaulle".

RUN GetWeather IN hPortType(
  INPUT CityName,
  INPUT CountryName,
  OUTPUT GetWeatherResult).

RUN ErrorInfo (OUTPUT err).
IF NOT err THEN DO:
    MESSAGE GetWeatherResult "~n"
     STRING(MTIME - li) " milisecondes."
     VIEW-AS ALERT-BOX.
END.
ELSE DO:
    retValue = "ERROR".
END.


DELETE PROCEDURE hPortType.
hWebService:DISCONNECT().
DELETE OBJECT hWebService.

RETURN retValue.
/*******************************************************************/
PROCEDURE ErrorInfo: /*1*/
  DEFINE OUTPUT PARAMETER errorfound AS LOGICAL INITIAL FALSE.
  DEFINE VARIABLE i                  AS INTEGER NO-UNDO.
  DEFINE VARIABLE hSOAPFault         AS HANDLE NO-UNDO.
  DEFINE VARIABLE hSOAPFaultDetail   AS HANDLE NO-UNDO.
  DEFINE VARIABLE HeaderXML AS LONGCHAR VIEW-AS EDITOR SIZE 70 BY 15 LARGE.
  IF ERROR-STATUS:NUM-MESSAGES > 0 THEN DO:
     errorfound = TRUE.
     DO i = 1 TO ERROR-STATUS:NUM-MESSAGES:
        MESSAGE ERROR-STATUS:GET-MESSAGE(i) VIEW-AS ALERT-BOX.
     END.
/*2*/
     IF VALID-HANDLE(ERROR-STATUS:ERROR-OBJECT-DETAIL) THEN DO:
       hSOAPFault = ERROR-STATUS:ERROR-OBJECT-DETAIL.
       MESSAGE
       "Fault Code: "   hSOAPFault:SOAP-FAULT-CODE        SKIP
       "Fault String: " hSOAPFault:SOAP-FAULT-STRING      SKIP
       "Fault Actor: "  hSOAPFault:SOAP-FAULT-ACTOR       SKIP
       "Error Type: "   hSOAPFault:TYPE  VIEW-AS ALERT-BOX.
/*3*/
       IF VALID-HANDLE(hSOAPFault:SOAP-FAULT-DETAIL) THEN  DO:
            hSOAPFaultDetail = hSOAPFault:SOAP-FAULT-DETAIL.
            MESSAGE  "Error Type: " hSOAPFaultDetail:TYPE
                     VIEW-AS ALERT-BOX.
            HeaderXML = hSOAPFaultDetail:GET-SERIALIZED().
            DISPLAY HeaderXML LABEL "Serialized SOAP fault detail"
                    WITH FRAME a.
        END.
     END.
  END.
END PROCEDURE.
/*******************************************************************/