Acceso a webservice para SII

Acceso a webservice para SII

Postby gmart1 » Wed Apr 05, 2017 6: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: Select all  Expand view
    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.
gmart1
 
Posts: 80
Joined: Wed Oct 24, 2007 12:48 pm
Location: Alhaurin de la Torre (MALAGA)

Re: Acceso a webservice para SII

Postby hmpaquito » Wed Apr 05, 2017 7: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: Select all  Expand view
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
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Acceso a webservice para SII

Postby gmart1 » 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: Select all  Expand view
    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
gmart1
 
Posts: 80
Joined: Wed Oct 24, 2007 12:48 pm
Location: Alhaurin de la Torre (MALAGA)

Re: Acceso a webservice para SII

Postby hmpaquito » 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: Select all  Expand view
   oHttp:WaitForResponse( 500 )
    cRetorno := oHttp:ResponseBody



Obtenido del ejemplo de Quintás.

Code: Select all  Expand view
    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
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: Acceso a webservice para SII

Postby AngelSalom » Fri Apr 07, 2017 9:06 am

Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
User avatar
AngelSalom
 
Posts: 708
Joined: Fri Oct 07, 2005 7:38 am
Location: Benicarló (Castellón ) - España

Re: Acceso a webservice para SII

Postby gmart1 » Fri Apr 07, 2017 3: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.
gmart1
 
Posts: 80
Joined: Wed Oct 24, 2007 12:48 pm
Location: Alhaurin de la Torre (MALAGA)


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 91 guests