

PUBLIC  oWS

oWS = CREATEOBJECT ('ClassWS')

oWS.ws_run3()


DEFINE CLASS ClassWS AS CUSTOM 

loSoapClientUrl = "http://69.20.52.167/eforce/wsInterfacesEc/InterfacesEc3.php?wsdl"

lscUser = ''
lcPwd = ''

FUNCTION ws_run (fun)
 	*!* Creando web Service
 	loSoapClient  = CREATEOBJECT("MSSOAP.SoapClient30")
 	
 	lcResult = 'vacio'
 
	IF VARTYPE(loSoapClient)=='O'
  		loSoapClient.MSSoapInit(this.loSoapClientUrl)
  		
  		TEXT TO cParam NOSHOW TEXTMERGE 
<login>
<servidorBaseDatos>www.ecom.com.co</servidorBaseDatos>  
  <nombreBaseDatos>natsilepru</nombreBaseDatos>  
  <usuarioBaseDatos>pedidos@natsilepru</usuarioBaseDatos>  
  <claveBaseDatos>Ecom2016</claveBaseDatos>  
  <fechaInicial>2015-01-01</fechaInicial>    
  <fechaFinal>2016-10-01</fechaFinal>
  <limiteRegistros>10</limiteRegistros>  
  <offset>0</offset>
<login>
  		ENDTEXT
  		
  	
  		DIMENSION aParam [1]
  		aParam [1] = cParam
  		
  		lcResult = loSoapClient.call(fun,aParam)
  		
 	ENDIF 

 	*!* Liberando WebService
 	RELEASE loSoapClient
 
 	MESSAGEBOX(lcResult)
 
	RETURN lcResult
ENDFUNC

FUNCTION ws_run3

	LOCAL loWS AS "XML Web Service"
	* LOCAL loWS AS "MSSOAP.SoapClient30"
	* Do not remove or alter following line. It is used to support IntelliSense for your XML Web service.
	*__VFPWSDef__: loWS = http://localhost/VFAC2SofmanService/ServicioVFAC2Sofman.asmx?WSDL , ServicioVFAC2Sofman , ServicioVFAC2SofmanSoap
	LOCAL loException, lcErrorMsg, loWSHandler
	TRY
		loWSHandler = NEWOBJECT("WSHandler",IIF(VERSION(2)=0,"",HOME()+"FFC\")+"_ws3client.vcx")
		
		&& "http://69.20.52.167/eforce/wsInterfacesEc/InterfacesEc3.php?wsdl"
		
	
		lcURI = this.loSoapClientUrl
		lcService = 'wsdl'
		lcPort = ''
		lcWSML = ''
		
		loWS = loWSHandler.SetupClient(lcURI, lcService, lcPort, lcWSML)
		*loWS = loWSHandler.SetupClient(lcURI)


		* Call your XML Web service here.  ex: leResult = loWS.SomeMethod()

  		TEXT TO cParam NOSHOW TEXTMERGE 
<login>
<servidorBaseDatos>www.ecom.com.co</servidorBaseDatos>  
  <nombreBaseDatos>natsilepru</nombreBaseDatos>  
  <usuarioBaseDatos>pedidos@natsilepru</usuarioBaseDatos>  
  <claveBaseDatos>Ecom2016</claveBaseDatos>  
  <fechaInicial>2015-01-01</fechaInicial>    
  <fechaFinal>2016-10-01</fechaFinal>
  <limiteRegistros>10</limiteRegistros>  
  <offset>0</offset>
<login>
  		ENDTEXT

  		DIMENSION aParam [1]
  		aParam [1] = cParam

		
		cresult = loWS.call('getPedido',aParam)
		cerr    = loWS.getError()

		IF (cerr == "")
			MESSAGEBOX(cresult)
		ELSE 
		 	MESSAGEBOX(cerr)
		ENDIF
		
		

		
	CATCH TO loException
		lcErrorMsg="Error: "+TRANSFORM(loException.Errorno)+" - "+loException.Message
		DO CASE
		CASE VARTYPE(loWS)#"O"
			* Handle SOAP error connecting to web service
		CASE !EMPTY(loWS.FaultCode)
			* Handle SOAP error calling method
			lcErrorMsg=lcErrorMsg+CHR(13)+loWS.Detail
		OTHERWISE
			* Handle other error
		ENDCASE
		* Use for debugging purposes
		MESSAGEBOX(lcErrorMsg)
	FINALLY
	ENDTRY


ENDFUNC


FUNCTION WS_RUN2()

#DEFINE SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS    13056 

loXmlHttp        = CREATEOBJECT("MSXML2.ServerXMLHTTP.6.0") 
loXMLBody        = CREATEOBJECT("MSXML2.DOMDocument.6.0") 
lcURL   = this.loSoapClientUrl

TEXT TO lcEnvioXML TEXTMERGE NOSHOW FLAGS 1 PRETEXT 1+2+4+8 
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://69.20.52.167/eforce/wsInterfacesEc/InterfacesEc3.php">
    <soapenv:Header/> 
    <soapenv:Body> 
        <web:getProductos> 
        <login>
			  <servidorBaseDatos>www.ecom.com.co</servidorBaseDatos>  
			  <nombreBaseDatos>natsilepru</nombreBaseDatos>  
			  <usuarioBaseDatos>pedidos@natsilepru</usuarioBaseDatos>  
			  <claveBaseDatos>Ecom2016</claveBaseDatos>  
			  <fechaInicial>2015-01-01</fechaInicial>    
			  <fechaFinal>2016-10-01</fechaFinal>
			  <limiteRegistros>10</limiteRegistros>  
			  <offset>0</offset>
		</login>
        </web:getProductos> 
    </soapenv:Body> 
</soapenv:Envelope> 
ENDTEXT 

IF NOT loXMLBody.loadXML( lcEnvioXML ) 
    ERROR loXMLBody.parseError.reason 
ENDIF 

*, this.lscUser, this.lcPwd

loXmlHttp.OPEN( "POST", lcURL, .F. ) 
loXmlHttp.setRequestHeader( "Accept-Encoding", "gzip,deflate" ) 
loXmlHttp.setRequestHeader( "Content-Type", "text/xml" ) 
*loXmlHttp.setRequestHeader( "Content-Type", "text/xml;charset=ISO-8859-1" ) 
loXmlHttp.setRequestHeader( "Content-Length", LEN(lcEnvioXML) ) 
loXmlHttp.setRequestHeader( "soapAction", "sendMailProcessBasica" ) 
loXmlHttp.setOption( 2, SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS ) 
         
loXmlHttp.SEND( loXMLBody.documentElement.XML ) 
         
IF loXmlHttp.status # 200 
    ERROR (NVL(loXmlHttp.responseText,'')) 
ENDIF 

*-- Aquí se lee el contenido del XML de la propiedad "loXmlHttp.responseText"

STRTOFILE(loXmlHttp.responseText,'\temp\ws.txt')



FUNCTION ws_get(cUrl)
	DECLARE INTEGER InternetCheckConnection in wininet STRING lpszUrl, INTEGER dwFlags, INTEGER dwReserved
	IF InternetCheckConnection(this.host, 1, 0) == 1 then
		username  = this.username
		lpassword = this.lpassword
		auth = Strconv(username + ":" + lpassword, 13)
		
		conexion = CREATEOBJECT( "MSXML2.ServerXMLHTTP" )
		conexion.open("GET",  url, .F.)
		conexion.setRequestHeader("Content-Type", "application/xml")
		conexion.setRequestHeader("Accept", "application/xml")
		conexion.setRequestHeader("Authorization", "Basic " + auth)
		
		lResolve = 5 * 1000
		lConnect = 5 * 1000
		lSend = 60 * 1000
		lReceive = 60 * 1000
		conexion.setTimeouts(lResolve, lConnect, lSend, lReceive);
		
		conexion.send()
		httpStatus = conexion.status
		response = conexion.responseText
		IF httpStatus = 200 THEN
			RETURN response
		ELSE
			IF httpStatus = 400 THEN
				oXML = CREATEOBJECT('MSXML2.DomDocument')
				oXML.ASYNC = .F.
				oXml.loadXML(response)		
				oRootNode 	= oXML.documentElement
				oNodeList = oRootNode.getElementsByTagName("mensaje")
				oNode = oNodeList.ITEM(0)
				loResult	= oNode.firstChild.nodeValue
				*MESSAGEBOX('Error ' + STR(codigoRespuestaHTTP) + " cuerpo de respuesta " + response)
				RETURN '@error: ' + loResult
			ELSE
				RETURN '@error: ' + STR(httpStatus)
			ENDIF
		ENDIF
	ENDIF
	
    RETURN  "@Error: No hay Conexion con el Servidor Web"
        
ENDFUNC

FUNCTION readNode (response, ctag)
	oXML = CREATEOBJECT('MSXML2.DomDocument')
	oXML.ASYNC = .F.
	oXml.loadXML(response)		
	oRootNode 	= oXML.documentElement
	oNodeList = oRootNode.getElementsByTagName(ctag)
	oNode = oNodeList.ITEM(0)
	loResult	= oNode.firstChild.nodeValue
	
	RETURN loResult

ENDFUNC



ENDDEFINE