Search code examples
phpnusoap

The nusoap client fails to run


as it says in the title, I am trying to make a calculator in which the user enters the numbers and it does the most basic operations. The problem is that the client part does not work when I run it, the screen remains blank, I have checked the routes with the libraries and they are perfectly fine so I don't know where the fault lies, here I attach the code for both the client and the server .

server code:

<?php

    error_reporting(0);
    include('lib/nusoap.php');

    $server = 'MiServicio';
    $servicio = new soap_server();

    $servicio->configureWSDL($server, 'urn:servidor');

    $servicio->register("calculadora",
    array("x" => "xsd:int", "y" => "xsd:int"),
    array("return" => "xsd:string")

    );

    function calculadora($x, $y, $operacion){
        if($operacion == "suma")
            return $x+$y;
        else if($operacion == "suma")
            return $x + $y;
        else if($operacion == "resta")
            return $x - $y;
        else if($operacion == "multiplica")
            return $x * $y;
        else if($operacion == "divide")
            return $x / $y;
        return 0;
      
    }

    $servicio->service(file_get_contents("php://input"));

?>

client code:

<?php

    error_reporting(0);
    include('lib/nusoap.php');

    $cliente = new nusoap_client("http://localhost:90/ejercicio3/servidorcaculadora.php?wsdl", true);

    $resultado = $cliente -> call("calculadora", array("x"=> '3','y' =>4,'operacion'=>'multiplica'));

    echo($resultado)

?>

Solution

  • when looking at the server.php (via browser): enter image description here

    You see thant operation is missing under then Input

    You need to change this line:

    array("x" => "xsd:int", "y" => "xsd:int", "operation" => "xsd:string"),
    

    After this change, operation is seen:

    enter image description here

    In your client you do send the parameter x as a string ("x"=> '3'),

    why not send it as int, like this: "x"=> 3 ?