Good day I have been using Laravel 5.6, and my project should consume a web service based on SOAP (WSDL). My specific question is: is it possible to do it with Laravel and if they had a tutorial or documentation to review it?
Good day I have been using Laravel 5.6, and my project should consume a web service based on SOAP (WSDL). My specific question is: is it possible to do it with Laravel and if they had a tutorial or documentation to review it?
Good morning. Of course, it is possible, I have consumed SAP clients that are through WSDL from laravel 5.4 and with the native library SoapClient
.
The first requirement is to enable the php_soap.dll
extension in the php.ini
. It is also important to know the structures of WSDL sources and they bring "methods" that you can invoke. Here is a small example that sends data in array format to a WSDL for accounting purposes.
// Creamos los datos de entrada
$asiento = [
'ubicacion1' => [
'total' => 3000,
'moneda' => 'USD'
],
'ubicacion2' => [
'total' => 4000,
'moneda' => 'USD'
]
];
// Este es el webservice que vamos a consumir
$wsdl = 'http://server1.com/sap/bc/srt/wsdl/flv_10002A101AD1/prueba';
// Creamos el cliente SOAP que hará la solicitud, generalmente están
// protegidos por un usuario y una contraseña
$cliente = new \SoapClient($wsdl, [
'login' => 'usuario',
'password' => 'contraseña',
'encoding' => 'UTF-8',
'trace' => true
]);
// Consumimos el servicio llamando al método que necesitamos, en este caso
// calcularCostos() es un método definido dentro del WSDL
$resultado = $cliente->calcularCostos($asiento);
// Finalmente muestras la respuesta
dd($resultado);
It's a basic but functional example.