im a beginner to programming and following a tutorial on web services with php and soap using Apache2.4 web server. the tutorial uses soap without wsdl file
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();
?>
Class used in server:
<?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;
}
}
?>
i keep getting this error:
object(SoapFault)#2 (10) { ["message":protected]=> string(33) "looks like we got no XML document"....................
so far i did the following:
the tutorial doesnt use a wsdl file, maybe i need to change more settings in php.ini?
what could be the problem???
Thanks in advance.
In PHP to check whether SOAP enabled or not use built in function class_exists() : var_dump(class_exists("SOAPClient")); It also could be user to check any of modules classes.
To make SOAP requests to the SOAP API endpoint, use the "Content-Type: application/soap+xml" request header, which tells the server that the request body contains a SOAP envelope. The server informs the client that it has returned a SOAP envelope with a "Content-Type: application/soap+xml" response header.
A PHP SOAP Extension can be used to provide and consume Web services. In other words, this PHP extension can be used by PHP developers to write their own Web Services, as well as to write clients to make use of the existing Web services.
WSDL stands for Web Services Description Language.
SOLVED
in soap_client.php, in catch, i added "echo $client->__getLastResponse();" which gave me the following output:
Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0
Warning: Cannot modify header information - headers already sent in Unknown on line 0
Dale Cooper, Harry Truman, Shelly Johnson, Bobby Briggs, Donna Hayward, Audrey Horne, James Hurley, Lucy Moran, Tommy Hill, Andy Brennan, John Smith
that last line is the string i passed to the client.
so what i tried was to uncomment "always_populate_raw_post_data = -1" in php.ini as the error suggested & restarted my Apache2.4 web-server and now it works, getting my string with no errors:
Dale Cooper, Harry Truman, Shelly Johnson, Bobby Briggs, Donna Hayward, Audrey Horne, James Hurley, Lucy Moran, Tommy Hill, Andy Brennan, John Smith
hope i helped someone with this, as i saw alot of unanswered questions about this error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With