I’m trying to make a SOAP web service work.
I have a XAMPP server installed and I use Visual Studio Code for coding. I’ve created a web service in a file called “servidorWs.php’. It’s content is the following:
function sumar($n1, $n2){
return $n1+$n2;
}
function restar($n1, $n2){
return $n1+$n2;
}
$uri ="localhost/34curso";
$servidor = new SoapServer(null, array('uri'=>$uri));
$servidor->addFunction("sumar");
$servidor->addFunction("restar");
$servidor->handle();
echo "Servidor de servicios web SOAP funcionando.";
And also I’ve created a web service consumer in the file “consumidorWs.php” with the following code:
Blockquote
//Al no especificar el wsdl del servicio web, debemos detallar el url donde
vamos a consumir el servicio
$url=”http://localhost/34curso/servidorWs.php”;
$uri=”http://localhost/34curso/”;
//Creamos el cliente con el segundo parámetro. El primero null
$cliente = new SoapClient(null, array(‘location’=>$url, ‘uri’=>$uri));
$numero = $cliente->sumar(5,4);
echo “valor de la suma “.$numero.”
“;
$numero = $cliente->restar(5,4);
echo “valor de la resta “.$resta;
Blockquote
I call the web server in Google Chrome and apparently it works.
But when I execute the client I get the following message:
Fatal error: Uncaught SoapFault exception: [Client] looks like we got no XML document in …consumidorWs.php:9 Stack trace: #0 … consumidorWs.php(9): SoapClient->__call(‘sumar’, Array) #1 {main} thrown in …consumidorWs.php on line 9.
Does anybody can help me?
Is it necesary to do anything to make the server works? I tried executing in the Terminal with no difference.
Thank you.
Best wishes.