我对网络服务和肥皂很陌生,我遵循了一个教程并附带了以下代码:
SOAP 服务器:
<?php
include("lib/nusoap.php");
include("getDB.php");
function getUsers()
{
$user_id = $_GET['user_id'];
$result = mysql_query("SELECT * FROM -table name- WHERE user_id = '$user_id'");
$try = mysql_fetch_array($result);
return join(",", array(
$result['username'], $result['password']
));
}
$server = new soap_server();
$server->register("getUsers");
$server->service($HTTP_RAW_POST_DATA);
?>
SOAP 客户端:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<!-- Error Reporting -->
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
</head>
<body>
<?php
include("lib/nusoap.php");
$client = new nusoap_client("http://localhost/wp-content/themes/blackbird/phpwizard/HTML5Application/public_html/Webservice.php?user_id=4");
$error = $client->getError();
if ($error)
{
echo "<h2>Constructor error</h2><pre>" . $error . "</pre>";
}
$result = $client->call("getUsers", array("category" => "books"));
if ($client->fault)
{
echo "<h2>Fault</h2><pre>";
print_r($result);
echo "</pre>";
}
else
{
$error = $client->getError();
if ($error)
{
echo "<h2>Error</h2><pre>" . $error . "</pre>";
}
else
{
echo "<h2>Books</h2><pre>";
echo $result;
echo "</pre>";
}
}
?>
</body>
</html>
现在加载 SOAP 客户端时出现错误:
第 3 行解析 SOAP 有效负载的 XML 错误:保留的 XML 名称
我不知道为什么会这样。