我想为Ipad应用程序创建一个Web服务,以便我可以在应用程序和Web服务器之间同步数据,请指导我。
我试图测试这个简单的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();
?>
答案 0 :(得分:1)
如果其他人绊倒了这段代码,就像我做的那样...... 我确实让这个例子工作得很好。最初我有一个“错误的版本”例外。您需要更改代码的所有内容是将URL添加到Soap服务器。
我添加了$autodiscover->setUri("http://some/path/to/soapserver/");
,它运行得很好。