未捕获的SoapFault异常:[SOAP-ENV:Server]函数method()的参数太少,传递了1个,恰好期望2个

尝试在我的SOAP服务器中使用该函数时出现此错误。我不知道我在做什么错,我看过大多数关于此错误的帖子,没有运气。我对PHP和SOAP极为陌生,因此对它的外观感到抱歉

这是我的PHP函数和SOAP服务器设置:

function getProductsByPrice($category,$price) {

    $conn = mysqli_connect('localhost','root','','my_guitar_shop1');

    if (!$conn) {
        die("Connection failed: " . $conn->connect_error);
    }

    $sql = "SELECT * FROM products WHERE categoryID = '$category' AND 
    listPrice < '$price'";
    $result = mysqli_query($conn,$sql);
    $rows = array();

    if (mysqli_num_rows($result) > 0) {
        while ($r = mysqli_fetch_assoc($result)) {

            array_push($rows,$r);
        }
        return json_encode($rows);
    } else {
        echo "No data";
    }
     }

       ini_set("soap.wsdl_cache_enabled","0");
       $server = new SoapServer("http://localhost/SOAPserverTest/LOI.wsdl");
       $server->addFunction(array("getProductsByPrice","showProductDetails","showTable"));
       $server->handle();
?>

这就是我使用方法的方式

<?php
    $category = 3;
    $price = 400;

    $client = new SoapClient("http://localhost/SOAPserverTest/LOI.wsdl");
    $response1 = $client->getProductsByPrice($category,$price);
    $result1 = json_encode($response1,TRUE);

    print $result1;
?>

当我访问客户端页面时,出现此错误:

  

致命错误:未捕获的SoapFault异常:[SOAP-ENV:Server]函数getProductsByPrice()的参数太少,传递了1个参数,在C:\ xampp \ htdocs \ finalSOAPClient \ model \ GetByPrice.php:7中恰好期望2个参数跟踪:#0 C:\ xampp \ htdocs \ finalSOAPClient \ model \ GetByPrice.php(7):SoapClient-> __ call('getProductsByPr ...',Array)#1 {main}抛出C:\ xampp \ htdocs \第7行的finalSOAPClient \ model \ GetByPrice.php

fandly_jw 回答:未捕获的SoapFault异常:[SOAP-ENV:Server]函数method()的参数太少,传递了1个,恰好期望2个

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3142345.html

大家都在问