2011-12-30 62 views
0

我想为Ipad应用程序创建一个Web服务,以便我可以在应用程序之间同步数据和Web服务器,请指导我。wsdl解析错误,未能加载外部实体“http:// localhost:10088/SoapService/public/testService.php?wsdl”

我试图测试这个简单的PHP脚本来测试和创建简单的Web服务,但我得到这个错误,我在哪里做错了?

<?php 

// Define path to application directory 
defined('APPLICATION_PATH') 
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); 

// Define application environment 
defined('APPLICATION_ENV') 
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production')); 

// Ensure library/ is on include_path 
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'), 
    get_include_path(), 
))); 

/** Zend_Application */ 
require_once 'Zend/Application.php'; 

// Create application, bootstrap, and run 
$application = new Zend_Application(
    APPLICATION_ENV, 
    APPLICATION_PATH . '/configs/application.ini' 
); 

require_once 'Zend/Loader/Autoloader.php'; 
require_once('Zend/Soap/AutoDiscover.php'); 
require_once('Zend/Soap/Server.php'); 
require_once('Zend/Soap/Client.php'); 
?> 
<?php 

class Login { 

    /** 
    * Add method 
    * 
    * @param Int $param1 
    * @param Int $param2 
    * @return Int 
    */ 
    public function math_add($param1, $param2) { 
     return $param1+$param2; 
    } 

    /** 
    * Logical not method 
    * 
    * @param boolean $param1 
    * @return boolean 
    */ 
    public function logical_not($param1) { 
     return !$param1; 
    } 

    /** 
    * Simple array sort 
    * 
    * @param Array $array 
    * @return Array 
    */ 
    public function simple_sort($array) { 
     asort($array); 
     return $array; 
    } 
} 

class LoginController 
{ 
    private $_WSDL_URI = "http://localhost:10088/SoapService/public/index.php?wsdl"; 

    public function init() 
    { 
    } 

    public function indexAction() 
    { 

     $this->hadleWSDL(); 

     if(isset($_GET['wsdl'])) { 
      //return the WSDL 
      $this->hadleWSDL(); 
     } else { 
      //handle SOAP request 
      $this->handleSOAP(); 
     } 
    } 

    private function hadleWSDL() { 
     $autodiscover = new Zend_Soap_AutoDiscover(); 
     $autodiscover->setClass('Login'); 
     $autodiscover->handle(); 
    } 

    private function handleSOAP() { 
     $soap = new Zend_Soap_Server($this->_WSDL_URI); 
     $soap->setClass('Login'); 
     $soap->handle(); 
    } 

    public function clientAction() { 
     $client = new Zend_Soap_Client($this->_WSDL_URI); 

     echo $client->math_add(11, 55); 
     echo $client->logical_not(true); 
     echo $client->simple_sort(array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple")); 

    } 

} 

$soapController = new LoginController(); 
$soapController->init(); 
$soapController->indexAction(); 
$soapController->clientAction(); 

?> 

回答

1

万一别人绊倒这个代码,像我一样...... 我没有得到这个例子中工作得很好。最初我有一个“错误的版本”异常。您需要更改的代码是将URL添加到Soap Server。

我加了$autodiscover->setUri("http://some/path/to/soapserver/");,它运行得很好。

相关问题