我直接从这里复制了以下代码: http://www.codeproject.com/Tips/671437/Creating-Web-Service-Using-PHP-Within-Minutes
服务器:
<?php
//call library
require_once ('nusoap.php');
//using soap_server to create server object
$server = new soap_server;
//register a function that works on server
$server->register('get_message');
// create the function
function get_message($your_name)
{
if(!$your_name){
return new soap_fault('Client','','Put Your Name!');
}
$result = "Welcome to ".$your_name .". Thanks for Your First Web Service Using PHP with SOAP";
return $result;
}
// create HTTP listener
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
客户端:
<?php
require_once ('nusoap.php');
//Give it value at parameter
$param = array( 'your_name' => 'Cool Guy');
//Create object that referer a web services
$client = new soapclient('http://localhost/SOAPServer.php');
//Call a function at server and send parameters too
$response = $client->call('get_message',$param);
//Process result
if($client->fault)
{
echo "FAULT: <p>Code: (".$client->faultcode."</p>";
echo "String: ".$client->faultstring;
}
else
{
echo $response;
}
?>
当我尝试访问客户端页面时,它显示以下错误:
FAULT:代码:(SOAP-ENV:Client
字符串:msg解析时出错:xml为空,没有解析!
我只需要这个简单的例子,这可能是什么问题?