php soap - SoapFault看起来我们没有XML文档

Nex*_*ddo 4 php soap web-services

我是编程的初学者,并使用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 = 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;

    }

}
?>
Run Code Online (Sandbox Code Playgroud)

我一直收到这个错误:

object(SoapFault)#2 (10) { ["message":protected]=> string(33) "looks like we got no XML document"....................
Run Code Online (Sandbox Code Playgroud)

到目前为止,我做了以下事情:

  1. php.ini中的extension = php_soap.dll已取消注释(已删除;)
  2. php_soap.dll在php\ext中找到
  3. 所有文件都以UTF-8编码,没有BOM
  4. 在php标记之后或之前没有尾随空格(据我所知)

教程不使用wsdl文件,也许我需要在php.ini中更改更多设置?

可能是什么问题呢???

提前致谢.

Nex*_*ddo 6

解决了

在soap_client.php中,在catch中,我添加了"echo $ client - > __ getLastResponse();" 这给了我以下输出:

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
Run Code Online (Sandbox Code Playgroud)

最后一行是我传递给客户端的字符串.

所以我试图在php.ini中取消注释"always_populate_raw_post_data = -1",因为错误建议并重新启动我的Apache2.4网络服务器,现在它可以工作,让我的字符串没有错误:

Dale Cooper, Harry Truman, Shelly Johnson, Bobby Briggs, Donna Hayward, Audrey Horne, James Hurley, Lucy Moran, Tommy Hill, Andy Brennan, John Smith
Run Code Online (Sandbox Code Playgroud)

希望我帮助这个人,因为我看到很多关于这个错误的未解答的问题.