我是一名编程初学者,正在学习使用 Apache2.4 Web 服务器使用 php 和 Soap 进行 Web 服务的教程。
本教程使用不带 wsdl 文件的soap
Client:
<?php
$options = array(
"location" => "http://localhost/web-services/soap_service.php",
"uri" => "http://localhost",
"trace" => 1,
);
try {
$client = new SoapClient(null, $options);
$students = $client->getStudentNames();
echo $students;
} catch(SoapFault $ex) {
echo var_dump($ex);
}
?>
Server:
<?php
require_once('Students.php');
$options = array("uri" => "http://localhost");
$server = new SoapServer(null, $options);
$server->setClass('Students');
$server->handle();
?>
服务器中使用的类:
<?php
class Students{
public function getStudentFirstName(){
$studentFN = array("Dale", "Harry", "Shelly", "Bobby",
"Donna", "Audrey", "James", "Lucy", "Tommy",
"Andy", "John");
return $studentFN;
}
public function getStudentLastName(){
$studentLN = array("Cooper", "Truman", "Johnson", "Briggs",
"Hayward", "Horne", "Hurley", "Moran", "Hill",
"Brennan", "Smith");
return $studentLN;
}
public function getStudentNames(){
$studentNames = "Dale Cooper, Harry Truman, Shelly Johnson, " .
"Bobby Briggs, Donna Hayward, Audrey Horne, " .
"James Hurley, Lucy Moran, Tommy Hill, " .
"Andy Brennan, John Smith";
return $studentNames;
}
}
?>
我不断收到此错误:
object(SoapFault)#2 (10) { ["message":protected]=> string(33) "looks like we got no XML document"....................
到目前为止我做了以下事情:
- php.ini 中的 extension=php_soap.dll 未注释(已删除;)
- php_soap.dll 位于 php\ext 中
- 所有文件均采用UTF-8无BOM编码
- php 标记之前或之后没有尾随空格(据我所知)
本教程不使用 wsdl 文件,也许我需要更改 php.ini 中的更多设置?
可能是什么问题呢???
提前致谢。