ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
*----------------------------------------------------------------------
* Variables para el Objeto WinHttpRequest
*----------------------------------------------------------------------
01 HttpJob pic x(128) value "WinHttp.WinHttpRequest.5.1".
01 WinHttpReq usage object reference OLE.
*> POST , GET , PUT
01 TipoEnvio pic x(4) value "POST".
* Verdero o falso dependiendo si la comunicacion es asyn - sync
01 OLE-TRUE PIC 1(1) BIT VALUE B"1".
01 OLE-FALSE PIC 1(1) BIT VALUE B"0".
*https:
01 ServerName pic x(256) value "http://ec.europa.eu/taxation_customs/vies/services/checkVatService".
01 ReqHead1 pic x(256) value "Content-Type".
01 ReqHead2 pic x(256) value "application/soap+xml; charset=utf-8".
01 status-string pic x(256).
01 Respuesta PIC x(450).
01 xTraffic-Conditions.
03 xtr01 pic x(42) value "<?xml version=""1.0"" encoding=""UTF-8""?>".
03 xtr02 pic x(80) value "<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"">".
03 xtr03 pic x(17) value " <SOAP-ENV:Body>".
03 xtr04 pic x(86) value " <tns1:checkVat xmlns:tns1=""urn:ec.europa.eu:taxud:vies:services:checkVat:types"">".
03 xtr05 pic x(24) value " <tns1:countryCode>".
03 xtrPais pic X(02) VALUE "PT". *>IT
03 XTR05A pic X(19) VALUE "</tns1:countryCode>".
03 xtr06 pic x(22) value " <tns1:vatNumber>". *> 03 XTRNIF pic X(11) VALUE "07392740960".
03 XTRNIF pic X(9) VALUE "510944299".
03 xtr06C pic x(17) value "</tns1:vatNumber>". *> falta del ejemplo de RUI
03 xtr07 pic x(16) value "</tns1:checkVat>".
03 xtr08 pic x(18) value " </SOAP-ENV:Body>".
03 xtr09 pic x(20) value "</SOAP-ENV:Envelope>".
01 Traffic-Conditions redefines xTraffic-Conditions pic x(374).
01 ReturnValue pic s9(5) comp-5 VALUE ZEROS.
01 Campo-Valida pic x(10).
01 Campo-Name pic x(30).
01 Campo-Address pic x(30).
PROCEDURE DIVISION.
*-----------------
INICIO-Peticion.
*-----------------------------
* Crea el objeto WinHttpRequest
invoke OLE "CREATE-OBJECT" using HttpJob returning WinHttpReq.
*------------------------------
* Open la HTTP request.
invoke WinHttpReq "OPEN" using TipoEnvio , ServerName , ole-true.
*
invoke WinHttpReq "setRequestHeader" using ReqHead1 ReqHead2.
*
* ------------------------------
* Envia HTTP request.
invoke WinHttpReq "send" using Traffic-Conditions.
*------------------------------
* Espera la respuesta completa
invoke WinHttpReq "WaitForResponse" using ole-true.
*-------------------------------
*--------------------------------------------
* Muestra Estado de comunicacion
invoke WinHttpReq "get-StatusText" returning status-string.
display "*---------------------------------*"
display "Respuesta Server: " , status-string
* ---------------------------------------------------------------------------
invoke WinHttpReq "get-Responsetext" RETURNING Respuesta.
display "*-------xml de salida--------*"
display Respuesta.
display "*-------fin de salida--------*".
* ---------------------------------------------------------------------------
Leo-Xml. *>chilkat xml
INVOKE ChilkatXml1 "LoadXml" USING Respuesta RETURNING ReturnValue.
if ReturnValue not = 1 then
INVOKE pow-self "DisplayMessage" USING "error"
exit program
end-if.
INVOKE ChilkatXml1 "TagContent" USING "valid" RETURNING Campo-Valida.
INVOKE ChilkatXml1 "TagContent" USING "name" RETURNING Campo-Name.
INVOKE ChilkatXml1 "TagContent" USING "address" RETURNING Campo-Address.
display "valid : " , Campo-Valida.
display "name : " , Campo-Name.
display "address:" , Campo-Address.
Marcadores