【发布时间】:2021-01-17 09:36:24
【问题描述】:
正如标题中所说,我正在尝试制作一个计算器,用户可以在其中输入数字并执行最基本的操作。问题是客户端部分在我运行时不起作用,屏幕保持空白,我已经检查了库的路线,它们非常好,所以我不知道故障出在哪里,这里附上代码客户端和服务器。
服务器代码:
<?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"));
?>
客户端代码:
<?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)
?>
【问题讨论】:
-
Nusoap 是一个非常奇怪的新代码库选择。据我所知,其原始维护者的最后一个版本大约是十年前,从那时起,已经做了最低限度的工作以使其在 PHP 的排序版本上运行。即使使用 SOAP 也是不寻常的,但如果你这样做了,为什么不使用内置的 PHP 类呢? php.net/soap