Quisiera saber como hacer en delphi para consumir el web service de AFIP de facturacion electronica. El caso es que importe la direccion del servicio con WSDL Importer.
Pero segun las especificaciones se debe enviar un xml de solicitud con los datos del comprobante. Pero con el WSDL importer obtengo esto:
ServiceSoap = interface(IInvokable)
['{05274D74-5C3D-E536-980E-D9CE5D67F5D9}']
function FECAESolicitar(const Auth: FEAuthRequest; const FeCAEReq: FECAERequest): FECAEResponse;
stdcall;
function FECompTotXRequest(const Auth: FEAuthRequest): FERegXReqResponse; stdcall;
function FEDummy: DummyResponse; stdcall;
function FECompUltimoAutorizado(const Auth: FEAuthRequest; const PtoVta: Integer; const CbteTipo:
Integer): FERecuperaLastCbteResponse; stdcall;
function FECompConsultar(const Auth: FEAuthRequest; const FeCompConsReq: FECompConsultaReq):
FECompConsultaResponse; stdcall;
function FECAEARegInformativo(const Auth: FEAuthRequest; const FeCAEARegInfReq: FECAEARequest):
FECAEAResponse; stdcall;
function FECAEASolicitar(const Auth: FEAuthRequest; const Periodo: Integer; const Orden: SmallInt):
FECAEAGetResponse; stdcall;
function FECAEASinMovimientoConsultar(const Auth: FEAuthRequest; const CAEA: string; const PtoVta:
Integer): FECAEASinMovConsResponse; stdcall;
function FECAEASinMovimientoInformar(const Auth: FEAuthRequest; const PtoVta: Integer; const CAEA:
string): FECAEASinMovResponse; stdcall;
function FECAEAConsultar(const Auth: FEAuthRequest; const Periodo: Integer; const Orden: SmallInt):
FECAEAGetResponse; stdcall;
function FEParamGetCotizacion(const Auth: FEAuthRequest; const MonId: string): FECotizacionResponse;
stdcall;
function FEParamGetTiposTributos(const Auth: FEAuthRequest): FETributoResponse; stdcall;
function FEParamGetTiposMonedas(const Auth: FEAuthRequest): MonedaResponse; stdcall;
function FEParamGetTiposIva(const Auth: FEAuthRequest): IvaTipoResponse; stdcall;
function FEParamGetTiposOpcional(const Auth: FEAuthRequest): OpcionalTipoResponse; stdcall;
function FEParamGetTiposConcepto(const Auth: FEAuthRequest): ConceptoTipoResponse; stdcall;
function FEParamGetPtosVenta(const Auth: FEAuthRequest): FEPtoVentaResponse; stdcall;
function FEParamGetTiposCbte(const Auth: FEAuthRequest): CbteTipoResponse; stdcall;
function FEParamGetTiposDoc(const Auth: FEAuthRequest): DocTipoResponse; stdcall;
function FEParamGetTiposPaises(const Auth: FEAuthRequest): FEPaisResponse; stdcall;
end;
como veran el metodo FECAESolicitar notomaun xml sino un objeto FEAuthRequest,otro FeCAERequest.
El caso es que entonces debo crear estos dos objetos y llenarlo en lugar de crear el xml de la factura?
Porque al hacer:
procedure TComprobante.envio();
var
RIOFactura:THTTPRIO;
CUITEmisor:string;
hoy:TDate;
request:FEAuthRequest;
archivoini:TIniFile;
cae:FECAERequest;
content:FECAEResponse;
fecae:FECAEDetResponse;
cabecera:FECAECabRequest;
detalle:FECAEDetRequest;
movimiento:ArrayOfFECAEDetRequest;
error:ArrayOfErr;
RioComp:THTTPRIO;
responseUltCte:FERecuperaLastCbteResponse;
resp:ArrayOfFECAEDetRequest;
begin
hoy:=StrToDate(FormatDateTime('yy/mm/dd',now));
archivoini:=TIniFile.Create(ExtractFilePath(Application.ExeName) + 'caja.ini');
CUITEmisor:= archivoini.ReadString('AFIP','CUIT','');
//creamos objeto request
request:=FEAuthRequest.Create;
request.Token:=self.token;
request.sign:=self.sign;
request.Cuit:= StrToInt64(CUITEmisor);
//obtenemos ultimo comprobante asociado.
RioComp:=THTTPRIO.Create(nil);
with RIOComp do
begin
WSDLLocation:='https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL';
Port:='ServiceSoap';
Service:='Service';
end;
//objeto de respuesta
responseUltCte:=FERecuperaLastCbteResponse.Create;
//invocamos el metodo
responseUltCte:=(RioComp as serviceSoap).FECompUltimoAutorizado(request,1,011);
error:=responseUltCte.Errors;
if error<>nil then
begin
ShowMessage(error[0].Msg);
end;
//creamos cabecera del comprobante
cabecera:=FECAECabRequest.Create;
cabecera.CantReg:=DataModule1.cdsticket.RecordCount;
cabecera.PtoVta:=1;
cabecera.CbteTipo:=011;
//creamos el detalle
detalle:=FECAEDetRequest.Create;
detalle.Concepto:=1;
detalle.DocTipo:=80;
detalle.DocNro:=20346787717;
detalle.CbteDesde:=responseUltCte.CbteNro + 1;
detalle.CbteHasta:=responseUltCte.CbteNro + 1;
detalle.CbteFch:=FormatDateTime('yyyymmdd',now);
detalle.ImpTotal:=DataModule1.cdstickettotal.AsVariant;
detalle.ImpTotConc:=0;
detalle.ImpNeto:=DataModule1.cdstickettotal.AsVariant;
detalle.ImpOpEx:=0;
detalle.ImpTrib:=0;
detalle.ImpIVA:=0;
detalle.FchVtoPago:=DateToStr(hoy);
detalle.MonId:='PES';
detalle.MonCotiz:=0;
//movieminto
SetLength(movimiento,1);
movimiento[0]:=detalle;
//creamos el objeto request
cae:=FECAERequest.Create;
//asignamos la cabecera
cae.FeCabReq:=cabecera;
cae.FeDetReq:=movimiento;
content:=FECAEResponse.Create;
//creamos objeto rio
RIOFactura:=THTTPRIO.Create(nil);
with RIOFactura do
begin
WSDLLocation:='https://wswhomo.afip.gov.ar/wsfev1/service.asmx?WSDL';
Port:='ServiceSoap';
Service:='Service';
end;
//invocamos el metodo
content:=(RIOFactura as serviceSoap).FECAESolicitar(request,cae);
if content.Errors<>nil then
begin
ShowMessage(content.Errors[0].Msg);
end
else
begin
ShowMessage(content.FeDetResp[0].CAE);
end;
end;
Fallan los tipos obviamente,el metodo delhttprionotoma un xml