nuSoap 没有显示出预期的结果

问题描述 投票:0回答:1

我是初学者,仍在学习中。

我有 nusoap 问题。我试图找出我的代码有什么问题,因为根据我搜索过的所有教程,我认为所有代码都是正确的。但当我运行 client.php 时,它仍然没有显示 server.php 的结果

PHP版本PHP/8.1.6

nusoap版本NuSOAP/0.9.11

这是我的server.php

<?php
 
// mengincludekan file berisi class nusoap
require_once 'nusoap.php';


// instansiasi class soap untuk server
$server = new soap_server();
$server->configureWSDL('server', 'urn:server');


// meregistrasi 'method' untuk proses penjumlahan dengan nama 'jumlahkan'
$server->register('jumlahkan');

 
// detil isi method 'jumlahkan'
function jumlahkan($x, $y) {
    return 'jumlahkan' . $x + $y ;
}
 
// memberikan response service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA: '';
$server->service(file_get_contents('php://input'));

?>

这是我的 client.php

<?php
 
require_once 'nusoap.php';

$wsdl = "http://localhost/WS/nusoap/server.php?wsdl";

// instansiasi obyek untuk class nusoap client
$client = new nusoap_client($wsdl, 'wsdl');

$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = FALSE;

$err = $client->getError();

if($err){
echo 'Error'.$err;
}
 
// dua bilangan yang akan dijumlahkan atau dikurangi
$bil1 = 10;
$bil2 = 25;

// proses call method 'jumlahkan' di script server.php yang ada di komputer B
$result = $client->call('jumlahkan', array('x' => $bil1, 'y' => $bil2));

echo "<p>Hasil penjumlahan ".$bil1." dan ".$bil2." adalah ".$result."</p>";
//print_r($result); 
 
 
// menampilkan format XML hasil response
echo '<h2>Respond</h2>';
echo '<pre>'.$client->response.'</pre>';

echo '<h2>Request</h2>';
echo '<pre>'.$client->request.'</pre>';
 
?>

错误

Fatal error:  Uncaught ArgumentCountError: Too few arguments to function jumlahkan(), 0 passed in D:\xampp\htdocs\WS\nusoap\nusoap.php on line 4204 and exactly 2 expected in D:\xampp\htdocs\WS\nusoap\server.php:17
Stack trace:
#0 D:\xampp\htdocs\WS\nusoap\nusoap.php(4204): jumlahkan()
#1 D:\xampp\htdocs\WS\nusoap\nusoap.php(3825): nusoap_server->invoke_method()
#2 D:\xampp\htdocs\WS\nusoap\server.php(26): nusoap_server->service('<?xml version="...')
#3 {main}
  thrown in D:\xampp\htdocs\WS\nusoap\server.php on line 17
php nusoap
1个回答
0
投票

数组,视为 1 个变量。在服务器端,您编写一个名为 jumlahkan() 的函数,该函数需要 2 个变量条目,在客户端,传递一个数组作为第一个变量,因此函数 jumlahkan() 中的第二个变量将为空并返回错误。

您可以在服务器端替换函数 jumlahkan(),如下所示:

function jumlahkan($array) {
    return 'jumlahkan' . $array['x'] + $array['y'];
}
© www.soinside.com 2019 - 2024. All rights reserved.