我制作了我的代码的简单版本。它没有给出任何错误,但它根本不起作用。(我为 PHP 启用了 Soap)
带函数的类:(Metodo.php)
class Teste {
/*
* @return string
*/
function SayHello() {
return "Hello, WORLD";
}
}
服务器:(Server.php)
<?php
require_once('Metodo.php');
if($_SERVER['QUERY_STRING'] == "wsdl") {
try {
require_once('Zend/Soap/AutoDiscover.php');
$wsdl = new Zend_Soap_AutoDiscover();
$wsdl->setClass('Teste');
$wsdl->handle();
}catch(exception $e) {
echo $e->getMessage();
}
} else {
$wsdl_url = sprintf('http://%s%s?wsdl', $_SERVER['HTTP_HOST'], $_SERVER['SCRIPT_NAME']);
require_once('Zend/Soap/Server.php');
$server = new SoapServer($wsdl_url);
$server->setClass('Teste');
$server->handle();
}
?>
客户端:(Client.php)
<?php
require_once('Zend/Soap/Client.php');
$wsdl_url = "http://localhost:8090/WebService/Server.php?wsdl";
$client = new Zend_Soap_Client($wsdl_url);
try {
echo $client->SayHello();
echo ":)";
} catch (SoapFault $e) {
echo $e->getMessage();
}
?>
它只是打印“:)”,没有错误,但它不会调用方法 SayHello()。如果有人愿意帮助我,我将不胜感激。真的。太感谢了。