你能帮我吗 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>';
 
?>

错误

致命错误:未捕获的 ArgumentCountError:函数 jumlahkan() 的参数太少,0 传入 D:\xampp\htdocs\WS 乌索普 usoap.php 位于第 4204 行,恰好是 D:\xampp\htdocs\WS 中预期的 2 个 usoap\server.php:17 堆栈跟踪: #0 D:\xampp\htdocs\WS 乌索普 usoap.php(4204): jumlahkan() #1 D:\xampp\htdocs\WS 乌索普 usoap.php(3825): nusoap_server->invoke_method() #2 D:\xampp\htdocs\WS usoap\server.php(26): nusoap_server->service('

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

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

function jumlahkan($array) {
    return 'jumlahkan' . $array['x'] + $array['y'];
}
php nusoap
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.