2015-06-30 25 views
4

即时通讯初学者编程和遵循使用PHP和SOAP使用Apache2.4 Web服务器的Web服务教程。 教程使用肥皂没有WSDL文件php肥皂 - SoapFault看起来像我们没有XML文档

客户:

<?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); 
} 
?> 

服务器:在服务器中使用

<?php 
require_once('Students.php'); 

$options = array("uri" => "http://localhost"); 
$server = new SoapServer(null, $options); 
$server->setClass('Students'); 
$server->handle(); 
?> 

类:

<?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; 

    } 

} 
?> 

我不断收到此错误:

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

到目前为止我做了以下:在php.ini

  1. 延长= php_soap.dll未被注释(已删除)
  2. php_soap.dll是以php \分机发现
  3. 所有文件
  4. 没有拖尾空格之后或之前的PHP标记(据我可以告诉)

教程d被编码UTF-8无BOM oesnt使用wsdl文件,也许我需要更改php.ini中的更多设置?

可能是什么问题?

在此先感谢。

+0

你是否重新启动Apache,因为取消注释'extension = php_soap.dll'这一行? –

+0

是的,几次 – ND88

回答

6

解决

在soap_client.php

,在捕捉,我增加 “回声$客户端 - > __ 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 

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

所以我尝试是取消注释“always_populate_raw_post_data = -1”在php.ini的错误建议&重新启动我的Apache2.4 Web服务器 和现在的作品,让我的字符串没有任何错误:

Dale Cooper, Harry Truman, Shelly Johnson, Bobby Briggs, Donna Hayward, Audrey Horne, James Hurley, Lucy Moran, Tommy Hill, Andy Brennan, John Smith 

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

+1

您的回答与问题无关。 –

+1

这是很大的解决方法,但没有解决问题... – Wizard

+1

它确实解决了我的问题 – Stupidfrog

0

我在我的wamp服务器中也遇到了这个问题。我在php.ini文件中设置了always_populate_raw_post_data = -1(通过删除;)然后重新启动服务器。它为我解决了这个问题。

相关问题