FoxPro/Visual FoxPro - consumir webservice para la dgii republica dominicana

 
Vista:

consumir webservice para la dgii republica dominicana

Publicado por jose camilo (805 intervenciones) el 25/09/2019 03:46:48
En este comparto como consultar la cedula o rnc en republica dominicana

solo me falto, pasar como parametro a text, en lo personal me dio trabajo y no lo termine
esta probado en windows 10 vfp9


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
oWS = CREATEOBJECT( "VFP_WebService","http://dgii.gov.do/wsMovilDGII/WSMovilDGII.asmx")
lcRespuesta = oWS.GetNATransaccion()
IF oWS.iStatus != 0
	MESSAGEBOX(oWS.sError,16,"Error al ejecutar WS")
ELSE
	MESSAGEBOX(lcRespuesta,64,"EjecutandoWS desde VFP")
ENDIF
 
DEFINE CLASS VFP_WebService AS CUSTOM
 
	sError = ""
	iStatus = 0
	sURL_WS = ""
 
	* --- Definimos la función del WebService ---
	FUNCTION GetNATransaccion ()
 
		     TEXT TO sXMLRequest TEXTMERGE NOSHOW
                  <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:dgii="http://dgii.gov.do/">
                  <soap:Header/>
                       <soap:Body>
                            <dgii:GetContribuyentes>
                                 <dgii:value>RNC_CEDULA</dgii:value>
                                 <dgii:patronBusqueda>0</dgii:patronBusqueda>
                                 <dgii:inicioFilas>0</dgii:inicioFilas>
                                 <dgii:filaFilas>0</dgii:filaFilas>
                                 <dgii:IMEI>?</dgii:IMEI>
                            </dgii:GetContribuyentes>
                       </soap:Body>
                  </soap:Envelope>
             ENDTEXT
 
 
		pXMLResponse = ADDBS(SYS(2023)) + SYS(2015) + [.xml]
 
		* --- Paso 2. Ejecuto el WS | Paso 3. Obtengo el Response ---
		this.iStatus =  this.EjecutaWS( this.sURL_WS, sXMLRequest , pXMLResponse, ["] + ALLTRIM(STR(LEN(sXMLRequest))) + ["])
 
		IF this.iStatus != 0  && Ocurrió un error el cual está especificado en sError.
			RETURN ""
		ENDIF
 
		sXMLResponse = Filetostr(pXMLResponse)
        sRespuestaWS = sXMLResponse
 
		this.borraArchivo(pXMLResponse)
 
		RETURN sRespuestaWS
 
	ENDFUNC
 
 
	*---------------------------------------------------
	FUNCTION EjecutaWS(pURL_WSDL, pFileRequest , pFileResponse, pLength )
	*---------------------------------------------------
	   TRY
	    oHTTP = CREATEOBJECT('Msxml2.ServerXMLHTTP.6.0')
	    oHTTP.OPEN("POST", pURL_WSDL, .F.)
	    oHTTP.setRequestHeader("Content-Type", "text/xml; charset=utf-8")
	    oHTTP.setRequestHeader("Content-Length",pLength)
	    oHTTP.setRequestHeader("SOAPAction","http://dgii.gov.do/GetContribuyentes")
	    oHTTP.SEND(pFileRequest)
	   CATCH TO loErr
	   		this.sError = "Error: " + TRANSFORM(loErr.ErrorNo) +  " Mensaje: " + loErr.Message
	   		this.iStatus = -1
	   ENDTRY
	   IF this.iStatus != 0
	   	RETURN -1
	   ENDIF
	    * --- Si el status es diferente a 200, ocurrió algún error de conectividad con el WS ---
	    IF oHTTP.STATUS = 200
	        RespuestaWS = oHTTP.responseText
		    * --- Se genera el XML del response | Este es el paso 3!! ---
 
		    STRTOFILE(STRCONV(RespuestaWS,9),pXMLResponse)
		    this.iStatus = 0
		    this.sError = ""
		    RETURN 0
	    ELSE
	        this.sError = "Error: No se logró la conexión con el Web Service."
	        this.iStatus = -1
			RETURN -1
	    ENDIF
	ENDFUNC
	*---------------------------------------------------
 
    *---------------------------------------------------
	FUNCTION BorraArchivo(pFile)
	*---------------------------------------------------
		IF FILE(pFile)
			DELETE FILE (pFile)
		ENDIF
	ENDFUNC
	*---------------------------------------------------
 
	*---------------------------------------------------
	* Evento constructor
	PROCEDURE Init
	*---------------------------------------------------
		LPARAMETERS tcURLWS
        this.sURL_WS = tcURLWS
        this.iStatus = 0
        this.sError = ""
	ENDPROC
	*---------------------------------------------------
ENDDEFINE
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder