【问题标题】:The nusoap client fails to runnusoap 客户端无法运行
【发布时间】: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

标签: php nusoap


【解决方案1】:

查看 server.php 时(通过浏览器):

你看到operation在然后输入下丢失了

你需要改变这一行:

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

在这个改变之后,operation 被看到了:

在您的客户端中,您确实将参数 x 作为字符串 ("x"=&gt; '3') 发送,

为什么不把它作为 int 发送,像这样:"x"=&gt; 3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 2015-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多