Ver Mensaje Individual
  #11  
Antiguo 25-12-2016
HubelSB HubelSB is offline
Registrado
 
Registrado: nov 2006
Posts: 9
Reputación: 0
HubelSB Va por buen camino
Tengo Respuesta

1). Con el WSDL Importer, darle la direccion del WS, para mi caso :

https://e-beta.sunat.gob.pe/ol-ti-it...llService?wsdl

se genera la unidad billService1.pas

la cual contiene la siguiente funcion GetbillService, ojo segun las versiones de delphi estas cambian en D7 y D2007 no se soportan los InvRegistry.RegisterParamInfo, si quieres generar un billService para versiones antiguas marca la opcion TXSxxxx for simple nillable, asi se genera un billservice capaz de usarse en versiones anteriores, yo estoy usando XE4 y bueno ahora D10.1 Berlin, esto de los webservices es mejor hacerlo con versiones nuevas, aunque las antiguas generan ejecutables mas rapidos.

2). Utilizar billservice1.pas

Para mi caso hay securidad ws-token, asi que para implementar la cabecera donde enviar el usuario y clave use THTTPReqResp

En un boton poner el siguiente codigo, ojo para la SUNAT peru, nos responde con un zip dentro del cual esta un xml con la respuesta si el documento ha sido aceptado o no, el archivo tiene que ser cargado en un array de bytes asi que lineas mas abajo te dejo los procedure que use.

Aun no termino el proyecto, ahora con wireshark estoy examinando como viajan los paquetes hacia el servidor, con la finalidad de ver si cumplen con el estandar que solicita SUNAT, cuando lo tengo listo lo libero hubelsolis@hotmail.com


procedure TForm1.Button1Click(Sender: TObject);
const
defWSDL = 'https://e-beta.sunat.gob.pe/ol-ti-itcpfegem-beta/billService?wsdl';
defURL = 'https://e-beta.sunat.gob.pe:443/ol-ti-itcpfegem-beta/billService';
defSvc = 'billService';
defPrt = 'BillServicePort';
var
tBillServ : billService;
Archivo : String;
Envio : TByteDynArray;
Respuesta : TByteDynArray;

HTTPReqResp1: THTTPReqResp;
HTTPRIO1 : THTTPRIO;
begin
HTTPReqResp1 := THTTPReqResp.create(nil);
HTTPReqResp1.Password := 'moddatos';
HTTPReqResp1.username := '20489697042MODDATOS';

HTTPRIO1 := THTTPRIO.Create(nil);
HTTPRIO1.HTTPWebNode := HTTPReqResp1;
HTTPRIO1.WSDLLocation := defWSDL;
HTTPRIO1.Service := defSvc;
HTTPRIO1.Port := defPrt;

// levanto el servicio
tBillServ:=GetbillService(TRUE,'',HTTPRIO1);
Archivo:='20489697042-03-BB01-00000003.ZIP';
envio:= FileToByteArray('D:\'+Archivo);

// envio
try
respuesta:=tBillServ.sendBill(Archivo,envio);
except
on E : Exception do
ShowMessage(E.ClassName+' error raised, with message : '+E.Message);
end;

ByteArrayToFIle(respuesta, 'D:\respuestas\rptab.zip' );

end;



procedure ByteArrayToFIle(const ByteArray : TByteDynArray; const FileName : string );
var Count : integer;
F : FIle of Byte;
pTemp : Pointer;
begin
AssignFile( F, FileName );
Rewrite(F);
try
Count := Length( ByteArray );
pTemp := @ByteArray[0];
BlockWrite(F, pTemp^, Count );
finally
CloseFile( F );
end;
end;

function FIleToByteArray( const FileName : string ) : TByteDynArray;
const BLOCK_SIZE=1024;
var BytesRead, BytesToWrite, Count : integer;
F : FIle of Byte;
pTemp : Pointer;
begin
AssignFile( F, FileName );
Reset(F);
try
Count := FileSize( F );
SetLength(Result, Count );
pTemp := @Result[0];
BytesRead := BLOCK_SIZE;
while (BytesRead = BLOCK_SIZE ) do
begin
BytesToWrite := Min(Count, BLOCK_SIZE);
BlockRead(F, pTemp^, BytesToWrite , BytesRead );
pTemp := Pointer(LongInt(pTemp) + BLOCK_SIZE);
Count := Count-BytesRead;
end;
finally
CloseFile( F );
end;
end;
Responder Con Cita