2011-12-30 61 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/");,它運行得很好。

相關問題