Inicio  |  Emisión  |  Ejemplos Consumir WebServices
La LCO fue actualizada por última vez el 23/jul./2025

Consuming Webservices

This section shows examples in some programming languages ​​for consuming Webservices.

Note: the examples in this section are based on the "Timbrado" WSDL. Each WSDL has its own structure and the request code must be modified according to the Webservices being connected.

VisualStudio2010
VisualStudio2010 C# .NET y VB .NET
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
 
$fname = "/tmp/cfdi_a_timbrar.xml";
if(!file_exists($fname)){
 die(PHP_EOL . "File not found" . PHP_EOL . PHP_EOL);
}
 
$handle = fopen($fname, "r");
$sData = '';
$usuario = "testing@solucionfactible.com";
$password = "timbrado.SF.16672";
 
while(!feof($handle))
    $sData .= fread($handle, filesize($fname));
fclose($handle);
$b64 = base64_encode($sData);
 
$response = '';
/*
Porfavor note:
    Este ejemplo está basado en el WSDL De timbrado
    cada WSDL tiene su propia estructura y deberá modificarse la petición
    acorde al webservice que se esté conectando.*/
try {
        $client = new SoapClient("https://testing.solucionfactible.com/ws/services/Timbrado?wsdl");
        $params = array('usuario' => $usuario, 'password' => $password, 'cfdiBase64'=>$b64, 'zip'=>False);
        $response = $client->__soapCall('timbrarBase64', array('parameters' => $params));
} catch (SoapFault $fault) {
        echo "SOAPFault: ".$fault->faultcode."-".$fault->faultstring."\n";
}
 
$ret = $response->return;
 
print_r("Estatus request: " . $ret->status . PHP_EOL);
print_r("Mensjae request: " . $ret->mensaje . PHP_EOL);
 
if($ret->status == 200) {
        print_r("Contenido resultados: " . PHP_EOL);
        print_r($ret->resultados);
}
?>

Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from zeep import Client
 
xmlFile = open("/tmp/cfdi-testing.xml", "rb")
xmlBytes = xmlFile.read()
xmlFile.close()
isZipFile = 0
 
result = client.service.timbrar('testing@solucionfactible.com', 'timbrado.SF.16672', xmlBytes, isZipFile)
if result.status == 200:#si la autenticación fue correcta y el servicio está disponible para el usuario
   resultadoTimbrado = result.resultados[0]
   print(resultadoTimbrado.status)
   print(resultadoTimbrado.mensaje)
   if resultadoTimbrado.status==200:#si el timbrado del comprobante fue exitoso
       print(resultadoTimbrado.uuid)
       print(resultadoTimbrado.cfdiTimbrado)
else:#ocurrió un error con la autenticación o la disponibilidad del servicio para el usuario
   print(result.mensaje)

Perl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use SOAP::Lite;
use MIME::Base64;
use POSIX qw(tzset);
 
my $TZ = 'America/Mexico_city';
 
$user = 'testing@solucionfactible.com';
$password = 'timbrado.SF.16672';
 
$file = 'ruta_al_cfdi.xml';
 
$base64 = "";
open(FILE, $file) or die "$!";
    while (read(FILE, $buf, 60*57)) {
    $base64 .= encode_base64($buf);
}
 
 
$response = SOAP::Lite->uri('http://timbrado.ws.cfdi.solucionfactible.com')->proxy($proxy)->timbrar($user, $password, $base64, false);
$status = $response->result->{'status'};
$mensaje = $response->result->{'mensaje'};
 
print "Status: $status\n";
print "Mensaje: $mensaje\n\n";
print "Detalle por comprobante\n";
for my $t ($response->valueof('//resultados')) {
        print "Status $t->{'status'}\nMensaje $t->{'mensaje'}\n";
        if(defined($t->{'uuid'})) {
                $ENV{TZ} = 'GMT';
                tzset;
                $fTimbrado = $t->{'fechaTimbrado'};
                print("UUID: $t->{'uuid'}\n");
                print("CFDI: ".decode_base64($t->{'cfdiTimbrado'})."\n");
                print("Fecha Timbrado: $fTimbrado\n");
                print("Cadena original: $t->{'cadenaOriginal'}\n");
                print("Certificado: $t->{'certificadoSAT'}\n");
                print("Sello: $t->{'selloSAT'}\n");
                print("QRCode: $t->{'qrCode'}\n");
        }
        print "\n\n";
}
print("\n\n");
Datos de contacto