我正在尝试创建一个 Web 服务,但我不明白这里有什么问题。
简单客户端.php
<?php
include_once("nusoap.php");
try {
// Create a soap client using SoapClient class
// Set the first parameter as null, because we are operating in non-WSDL mode.
// Pass array containing url and uri of the soap server as second parameter.
$client = new SoapClient(null, array(
'location' => "http://www.example.com/SimpleServer.php",
'uri' => "http://www.example.com"));
// Read request parameter
$param = $_POST['name'];
// Invoke AddHello() method of the soap server (HelloServer)
$result = $client->AddHello($param);
echo $result; // Process the the result
echo "test";
}
catch(SoapFault $ex) {
$ex->getMessage();
echo 'test';
}
?>
简单服务器.php
<?php
include_once("nusoap.php");
// Simple Method get 1 parameter and return with Hello
function AddHello($name)
{
return "Hello $name";
}
// Create SoapServer object using WSDL file.
// For the simplicity, our SoapServer is set to operate in non-WSDL mode. So we do not need a WSDL file
$server = new SoapServer(null, array('uri'=>'http://www.example.com'));
// Add AddHello() function to the SoapServer using addFunction().
$server->addFunction("AddHello");
// To process the request, call handle() method of SoapServer.
$server->handle();
?>
简单视图.php
<?php
echo "<h2>Welcome to PHP Web Service</h2>";
echo "<form action='SimpleClient.php' method='POST'/>";
echo "<input name='name' /><br/>";
echo "<input type='Submit' name='submit' value='Send'/>";
echo "</form>";
?>
当我调用 www.example.com/SimpleView.php 并将其进程的任何单词输入到 SimpleClient.php 时,没有显示任何结果。
我正在关注本教程。