Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php soap - SoapFault looks like we got no XML document

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:

  1. extension=php_soap.dll in php.ini is uncommented (removed ;)
  2. php_soap.dll is found in php\ext
  3. all files are encoded in UTF-8 without BOM
  4. no trailing white spaces after or before the php marks (as far as i can tell)

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.

like image 461
Netanel Draiman Avatar asked Jun 30 '15 21:06

Netanel Draiman


People also ask

How can I tell if SOAP is enabled in PHP?

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.

How can make SOAP call in PHP?

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.

What is PHP SOAP Extension?

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.

What is WSDL PHP?

WSDL stands for Web Services Description Language.


1 Answers

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.

like image 68
Netanel Draiman Avatar answered Nov 15 '22 00:11

Netanel Draiman