Web Service con HMG

HMG en Español

Moderator: Rathinagiri

Post Reply
User avatar
edufloriv
Posts: 235
Joined: Thu Nov 08, 2012 3:42 am
DBs Used: DBF, MariaDB, MySQL, MSSQL, MariaDB
Location: PERU

Web Service con HMG

Post by edufloriv »

Saludos amigos,

Pues bien, imagino que me llegó lo que me tenia que llegar, la empresa en la que laboro ha sido nombrada emisor electrónico por la SUNAT, había estado evitando este tema, pero creo que debo empezar a entenderlo. Para iniciar no tengo experiencia con Web Service, ya me empapé un poco del tema para no parecer 100% ignorante, pero tengo algunas dudas que agradecería me ayuden a entender.

Acá en Perú adicionalmente a la SUNAT, como nos dedicamos al comercio de medicamentos también nos controla la DIGEMID (Dirección General de Medicamentos y Drogas) a este se debe pasar mensualmente los precios de los medicamentos. Actualmente lo levantamos a través de su portal con una hoja de excel (nos dan esa opción) pero también ponen a disposición Web Service y al respecto ponen a disposición este esquema:

Code: Select all

POST /ServicePrecios.asmx HTTP/1.1
Host: localhost
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/ActualizarProducto"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthHeader xmlns="http://tempuri.org/">
<Username>string</Username>
<Password>string</Password>
</AuthHeader>
</soap:Header>
<soap:Body>
<ActualizarProducto xmlns="http://tempuri.org/">
<idSucursal>string</idSucursal>
<pre>
<IdProducto>int</IdProducto>
<PrecioMinUnit>double</PrecioMinUnit>
<PrecioMaxEmpaq>double</PrecioMaxEmpaq>
<PrecioPromedio>double</PrecioPromedio>
<Fecha>dateTime</Fecha>
</pre>
</ActualizarProducto>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ActualizarProductoResponse xmlns="http://tempuri.org/">
<ActualizarProductoResult>string</ActualizarProductoResult>
</ActualizarProductoResponse>
</soap:Body>
</soap:Envelope>
Pues bien, esto es SOAP 1.1 y a continuación enumero mis dudas:

1. Alguien tiene la bondad de pasarme código de ejemplo HMG 3.0.46 para usar Web Service por favor.
2. He buscado por internet y no me queda claro que debo poner en el campo "Content-Length:" length es el número de caracteres o que ? desde donde los cuento ?
3. Como sé que SOAP debo usar SOAP 1.1 o SOAP 1.2 ?
4. Tienen código de ejemplo de HMG 3.0.46 para la recepción de la respuesta que enviará el servidor ?
5. Alli en el campo <Fecha> dice dateTime pero no entiendo porque si todo esto es texto ? En todo caso debieron poner el formato AAAAMMDD, DD/MM/AAAA, etc.

Creo que lo entenderé mejor si alguien me alcanza un ejemplo en HMG 3.0.46. Apelando a su paciencia y generosidad, quedo de Ustedes.


Att.

Eduardo Flores Rivas


LIMA - PERU
User avatar
danielmaximiliano
Posts: 2607
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Contact:

Re: Web Service con HMG

Post by danielmaximiliano »

Hola Edu, aqui se usa algo parecido llamado Factura Electronica (FE) por la AFIP (agencia federal de ingresos publicos) y tienes algo mas o menos que te puede servir aqui http://hmgforum.com/download/file.php?id=5386

no tengo un disco a mano con una aplicacion funcional lo hare mañana para enviarte el archivo...

tambien puedes leer aaqui : https://tisoft.wordpress.com/category/consultas-sunat/
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO
gvaronas
Posts: 109
Joined: Wed Aug 06, 2008 5:21 pm

Re: Web Service con HMG

Post by gvaronas »

Hola Eduardo:
Andamos en las mismas.
Sobre el tema de Facturación Electrónica, en SUNAT hay bastante DOC, bájate el Manual del Programador.
Creo que Harbour es lo suficientemente poderoso y está preparado para afrontar este tipo de soluciones, yo programo en modo consola.

Salu2,
GVS
User avatar
edufloriv
Posts: 235
Joined: Thu Nov 08, 2012 3:42 am
DBs Used: DBF, MariaDB, MySQL, MSSQL, MariaDB
Location: PERU

Re: Web Service con HMG

Post by edufloriv »

Hola Daniel,

Mil gracias por tu ayuda, estuve indagando y bueno encontré este ejemplo, aún no lo he probado, pero me parece algo sencillo de leer y por donde empezar, no se porque en este ejemplo la creación del XML se ve super sencilla. Tambén he visto ese link de la factura electrónica que amablemente me alcanzaste, gracias, esta genial y veo que es completo, pero hay que desmenuzarlo para entenderlo y adaptarlo.

Code: Select all

#include "hbcurl.ch"
#include "common.ch"
#include "fileio.ch"

function main()
local cxml,canswer,nn1

// we try 12345 for CityZIP
ccityZIP := "12345"

cxml := '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:weat="http://ws.cdyne.com/WeatherWS/">'+chr(13)+chr(10)
cxml += "<soap:Header/>"+chr(13)+chr(10)
cxml += "<soap:Body>"+chr(13)+chr(10)
cxml += "<weat:GetCityForecastByZIP>"+chr(13)+chr(10)
cxml += "<weat:ZIP>"+ccityZIP+"</weat:ZIP>"+chr(13)+chr(10)
cxml += "</weat:GetCityForecastByZIP>"+chr(13)+chr(10)
cxml += "</soap:Body>"+chr(13)+chr(10)
cxml += "</soap:Envelope>"+chr(13)+chr(10)

canswer := fHttpExecute(cxml)
canswer := strtran(canswer,"><",">"+chr(10)+"<")
memowrit("soapanswer.txt",canswer)

quit
return .t.



function fHttpExecute(cxml)
local endpointUrl,curlHandle,curlErr
local aHeader,cc1

cc1 := ""

endpointUrl = "http://wsf.cdyne.com/WeatherWS/Weather.asmx"

aHeader := {}
AADD(aHeader,"Accept-Encoding: gzip,deflate" )
AADD(aHeader,"Content-Type: text/xml;charset=UTF-8" )
AADD(aHeader,'SOAPAction: "http://ws.cdyne.com/WeatherWS/GetCityForecastByZIP"' )
*AADD(aHeader,"User-Agent: Jakarta Commons-HttpClient/3.1"  )

curlHandle := curl_easy_init()

if !empty(curlHandle)

/* Specify the Header  data */
curl_easy_setopt(curlHandle,HB_CURLOPT_HTTPHEADER,aHeader)

/* Set the endpoint to send the POST to */
curl_easy_setopt(curlHandle, HB_CURLOPT_URL, endpointUrl)

/* Setup response data */
curl_easy_setopt( curlHandle, HB_CURLOPT_DOWNLOAD )
curl_easy_setopt( curlHandle, HB_CURLOPT_DL_BUFF_SETUP )

/* Specify the POST data */
curl_easy_setopt(curlHandle, HB_CURLOPT_POST, 1)
curl_easy_setopt(curlHandle, HB_CURLOPT_POSTFIELDS, cxml)

/* Do everything */
curlErr := curl_easy_perform(curlHandle)

/* Report any errors */
if empty(curlErr)
/* store response in variable */
cc1 := curl_easy_dl_buff_get( curlHandle )
else
? curl_easy_strerror(curlErr)
endif
else
? "No handle"
endif

if !empty(curlHandle)
/* Clean-up libcurl */
curl_global_cleanup( curlHandle )
else
? "Error"
endif

if empty(cc1)
? "Error"
endif

return cc1
Agradeceré toda la ayuda que puedas brindarme al respecto.

Un gran abrazo y recibe un cordial saludo de mi parte.

Eduardo Flores Rivas


LIMA - PERU
chrisjx2002
Posts: 190
Joined: Wed Jan 06, 2010 5:39 pm

Re: Web Service con HMG

Post by chrisjx2002 »

Very interesting. Where can I find hbcurl.ch to compile the program?
mlnr
Posts: 126
Joined: Fri Aug 28, 2015 1:52 pm
DBs Used: DBF

Re: Web Service con HMG

Post by mlnr »

chrisjx2002 wrote:Very interesting. Where can I find hbcurl.ch to compile the program?

hmg_dir\HARBOUR\contrib\hbcurl\
Best regards,
Gabor
chrisjx2002
Posts: 190
Joined: Wed Jan 06, 2010 5:39 pm

Re: Web Service con HMG

Post by chrisjx2002 »

Thanks for your answer. But when I compile the program, the error message is impossible to find hbcurl.ch. I look at the forum and there are a few messages about hbcurl.

I have copied hbcurl.ch hbcurl.hbc and hbcurl.hbx in the directory of the program.
I have modified hmg32.hbc and add libs=libhbcurl and libs=libhbcurls and rebuild the lib using BuildAllLib32.bat
I have copied libhbcurl.a et libhbcurls.a in \lib but I have still an error message

Harbour 3.2.0dev (r1601151502)
Copyright (c) 1999-2015, http://harbour-project.org/
c:/hmg.3.4.3/mingw/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w64-mi
ngw32/bin/ld.exe: cannot find -llibhbcurl
c:/hmg.3.4.3/mingw/bin/../lib/gcc/i686-w64-mingw32/5.3.0/../../../../i686-w64-mi
ngw32/bin/ld.exe: cannot find -llibhbcurls
collect2.exe: error: ld returned 1 exit status
hbmk2: Error: Running linker. 1
gcc.exe C:/DOCUME~1/CHRIST~1/LOCALS~1/Temp/hbmk_j05ens.dir/xml.o C:/DOCUME~1/CHR
IST~1/LOCALS~1/Temp/hbmk_j05ens.dir/hbmk_yeda5b.o G:/Programmes/xml/_temp.o -
mwindows -Wl,--start-group -lhmg -lcrypt -ledit -leditex -lgraph -lini -lreport
-lhfcl -lmsvfw32 -lvfw32 -lhbct -lhbwin -lhbmzip -lminizip -lhbmemio -lhbmisc -l
hbmysql -lmysql -lhbtip -lsqlite3 -lhbsqlit3 -lsddodbc -lrddsql -lsddmy -lhbodbc
-lodbc32 -lhbhpdf -lhbfimage -lhbpgsql -lhbnetio -lxhb -lpng -llibhpdf -lhbvpdf
-lhbzebra -llibhbcurl -llibhbcurls -lhbextern -lhbdebug -lhbvmmt -lhbrtl -lhbla
ng -lhbcpage -lgtcgi -lgtpca -lgtstd -lgtwin -lgtwvt -lgtgui -lhbrdd -lhbuddall
-lhbusrrdd -lrddntx -lrddcdx -lrddnsx -lrddfpt -lhbrdd -lhbhsx -lhbsix -lhbmacro
-lhbcplr -lhbpp -lhbcommon -lhbmainwin -lkernel32 -luser32 -lgdi32 -ladvapi32 -
lws2_32 -liphlpapi -lwinspool -lcomctl32 -lcomdlg32 -lshell32 -luuid -lole32 -lo
leaut32 -lmpr -lwinmm -lmapi32 -limm32 -lmsimg32 -lwininet -lhbpcre -lhbzlib -
Wl,--end-group -oxml.exe -Lc:/hmg.3.4.3/harbour/lib/win/mingw -Lc:/hmg.3.4.3/li
b


I am doing something wrong but what? Any help will be appreciated
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Web Service con HMG

Post by serge_girard »

I got the same errors. Is it HMG compile-able?

Serge
There's nothing you can do that can't be done...
mlnr
Posts: 126
Joined: Fri Aug 28, 2015 1:52 pm
DBs Used: DBF

Re: Web Service con HMG

Post by mlnr »

Yes Serge, i use this.

Please see the link.
viewtopic.php?f=5&t=4617
Best regards,
Gabor
User avatar
serge_girard
Posts: 3158
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Web Service con HMG

Post by serge_girard »

Thanks!
Serge
There's nothing you can do that can't be done...
Post Reply