FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Acceso a webservice para SII
Posts: 84
Joined: Wed Oct 24, 2007 12:48 PM
Acceso a webservice para SII
Posted: Wed Apr 05, 2017 06:30 PM
Buenas tardes,
estoy haciendo pruebas para acceder al webservice de hacienda y poder enviar y recibir ficheros XML para el Suministro Inmediato de Informaci贸n.
Este trozo de c贸digo :
Code (fw): Select all Collapse
聽 聽 local oHttp, cXML
聽 聽 local cUrl := "https://www7.aeat.es/wlpl/SSII-FACT/ws/fe/SiiFactFEV1SOAP"

聽 聽 cXML := MEMOREAD ( "SIIEmi.XML" )

聽 聽 oHttp := CreateObject ("MSXML2.XMLHTTP")

聽 聽 if oHttp = Nil
聽 聽 聽 聽 ? 'Erro de creacion oHttp'
聽 聽 endif
聽 聽 oHttp:Open ( "POST", cUrl, .f. )
聽 聽 oHttp:SetRequestHeader ( "Content-Type", "text/xml;charset=UTF-8")
聽 聽 oHttp:SetRequestHeader ( "SOAPAction:", "" )
聽 聽 oHttp:SetRequestHeader ( "Connection:", "Keep-Alive")
聽 聽 oHttp:SetRequestHeader ( "Content-length", STR (LEN(cXML) ) )

聽 聽 try
聽 聽 聽 聽 oHttp:Send ( cXML )
聽 聽 catch
聽 聽 聽 聽 ? oHttp:status
聽 聽 聽 聽 ? 'Error en Send'
聽 聽 聽 聽 return .t.
聽 聽 end
聽 聽 ? oHttp:responseText

La l铆nea oHttp:status me devuelve 12004
He buscado en internet este n煤mero de status y no encuentro que puede ocurrir, ya s茅 que me falta usar un certificado digital pero no parece que sea lo que me est谩 indicando ese c贸digo.

Muchas gracias por la ayuda.
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Acceso a webservice para SII
Posted: Wed Apr 05, 2017 07:01 PM
Hay que tener instalado un certificado digital valido en el ordenador desde el que se llama al WS de la aeat, sino no funciona, y hay que decirle el nombre al WS.

Y hay que decirselo asi:

Code (fw): Select all Collapse
oHttp:SetOption(2, 聽13056)
oHttp:setOption(3, "C:\Documents and Settings\"tu usuario"\Datos de programa\Microsoft\System Certificates\My\Certificates\XXXXXXXXXXXXXXXXXXXXXXXX") // donde XXXXXXXXXXXXXXXXXXXXXXXX es el nombre de tu certificado.



Aqu铆 hay un buen ejemplo del tema:

http://www.pctoledo.com.br/forum/viewto ... 30#p100267
Posts: 84
Joined: Wed Oct 24, 2007 12:48 PM
Re: Acceso a webservice para SII
Posted: Thu Apr 06, 2017 11:41 AM
Gracias hmpaquito, he realizado cambios seg煤n el enlace que me recomendaste y el c贸digo ha quedado as铆 :
Code (fw): Select all Collapse
聽 聽 local oHttp, cXML
聽 聽 local cUrl := "https://www7.aeat.es"

聽 聽 try
聽 聽 聽 聽 oHttp := win_OleCreateObject ("MSXML2.ServerXMLHTTP") 聽 && CreateObject ("MSXML2.XMLHTTP")
聽 聽 catch
聽 聽 聽 聽 ? 'Error de creacion oHttp'
聽 聽 聽 聽 return .t.
聽 聽 end

聽 聽 oHttp:SetOption(2, 13056)聽 
聽 聽 oHttp:SetOption(3, "C:\Users\apoyo3\AppData\Roaming\Microsoft\SystemCertificates\My\Certificates\BFC7148ACEE713342C714604600C8BEE2417F631" )
聽 聽 oHttp:Open ( "POST", cUrl, .f. )
聽 聽 oHttp:SetRequestHeader ( "Content-Type", "text/xml;charset=UTF-8")
聽 聽 oHttp:SetRequestHeader ( "Connection", "Keep-Alive")
聽 聽 oHttp:SetRequestHeader ( "SOAPAction", "/wlpl/SSII-FACT/ws/fe/SiiFactFEV1SOAP" )

聽 聽 cXML := MEMOREAD ( "SIIEmi.XML" )

聽 聽 try
聽 聽 聽 聽 oHttp:Send ( cXML )
聽 聽 catch
聽 聽 聽 聽 ? oHttp:readyState
聽 聽 聽 聽 ? 'Error en Send'
聽 聽 聽 聽 return .t.
聽 聽 end
聽 聽 ? oHttp:status
聽 聽 ? oHttp:ResponseText
return Nil

He tenido que crear el objeto MSXML2.ServerXMLHTTP para poder usar SetOption, no tengo muy claro el motivo, pero de esta forma el programa llega al Send y me da en oHttp:readyState el valor 1.
C贸mo puedo saber el motivo de error del Send, hay alguna propiedad de oHttp que lo refleje ?
He intentado oHttp:Status pero da este error :
Error description: (DOS Error -2147352567) WINOLE/1007 El dato necesario para completar esta operaci贸n no est谩 disponible todav铆a. (0x8000000A): msxml3.dll
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: Acceso a webservice para SII
Posted: Thu Apr 06, 2017 11:56 AM
gmart1,

Seg煤n el ejemplo de Quint谩s, para obtener la respuesta se utiliza ResponseBody, asi hay que poner:
Code (fw): Select all Collapse
 聽 聽oHttp:WaitForResponse( 500 )
聽 聽 cRetorno := oHttp:ResponseBody



Obtenido del ejemplo de Quint谩s.

Code (fw): Select all Collapse
 聽 聽 oServer := win_OleCreateObject( "MSXML2.ServerXMLHTTP" )
聽 聽 聽IF ::cCertificado != NIL
聽 聽 聽//oServer:setOption( 2, oServer:getOption( 2 ) - SXH_SERVER_CERT_IGNORE_CERT_DATE_INVALID )
聽 聽 聽oServer:setOption( 3, "CURRENT_USER\MY\" + ::cCertificado )
聽 聽 聽ENDIF
聽 聽 聽oServer:Open( "POST", ::cWebService, .F. )
聽 聽 聽oServer:SetRequestHeader( "SOAPAction", cSoapAction )
聽 聽 聽oServer:SetRequestHeader( "Content-Type", "application/soap+xml; charset=utf-8" )
聽 聽 oServer:Send( ::cXmlSoap )

聽 聽 oServer:WaitForResponse( 500 )
聽 聽 cRetorno := oServer:ResponseBody

聽 聽 msgInfo(cRetorno, "Esto puede ser muy grande")


Salu2
Posts: 728
Joined: Fri Oct 07, 2005 07:38 AM
Re: Acceso a webservice para SII
Posted: Fri Apr 07, 2017 09:06 AM
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
Posts: 84
Joined: Wed Oct 24, 2007 12:48 PM
Re: Acceso a webservice para SII
Posted: Fri Apr 07, 2017 03:43 PM

Gracias Angel, ya hab铆a visto este enlace, pero hab铆a pensado que podr铆a conseguir hacer la conexi贸n al webservice de hacienda por mi mismo.
Esta claro que mi poca experiencia en este tema y la poca informaci贸n que dan en hacienda no me va a permitir realizarlo.

Continue the discussion