Reputation: 691
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.
Upvotes: 5
Views: 17484
Reputation: 5179
I also faced this issue in my wamp server. I set the always_populate_raw_post_data = -1
in php.ini file (by removing the ;
) and then restart the server. It solved this issue for me.
Upvotes: 0
Reputation: 691
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.
Upvotes: 7