我是编程的初学者,并使用Apache2.4 Web服务器使用php和soap进行Web服务教程.本教程使用不带wsdl文件的soap
客户:
<?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);
}
?>
Run Code Online (Sandbox Code Playgroud)
服务器:
<?php
require_once('Students.php');
$options = array("uri" => "http://localhost");
$server = new SoapServer(null, $options);
$server->setClass('Students');
$server->handle();
?>
Run Code Online (Sandbox Code Playgroud)
服务器中使用的类:
<?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 …Run Code Online (Sandbox Code Playgroud)