我使用 Zend 框架创建了一个身份验证 Web 服务这是我的服务器:
<?php
require_once APPLICATION_PATH . '/controllers/services/Authentification.php';
class ServController extends Zend_Controller_Action
{
private $_WSDL_URI = 'http://127.0.0.1/EverTags1/webAuthentification/public/Serv/?wsdl';
public function init()
{
}
public function indexAction()
{
$this->_helper->viewRenderer->setNoRender();
if(isset($_GET['wsdl'])) {
$this->hadleWSDL(); //return the WSDL
} else {
$this->handleSOAP(); //handle SOAP request
}
}
private function hadleWSDL()
{
$autodiscover = new Zend_Soap_AutoDiscover();//Zend_Soap_AutoDiscover which will create the WSDL file
$autodiscover->setClass('Authentification');// class that we use as webservice
$autodiscover->handle();
}
public function handleSOAP()
{
$soap = new Zend_Soap_Server($this->_WSDL_URI);
$soap->setClass('Authentification');
$soap->handle();
}
}
客户:
<?php
class ClientController extends Zend_Controller_Action
{
private $_WSDL_URI = 'http://127.0.0.1/EverTags1/webAuthentification/public/Serv/?wsdl';
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$client = new Zend_Soap_Client($this->_WSDL_URI);
$this->view->UserInformation = $client->authentification('marwa','password');
}
}
我用作网络服务的类
<?php
ini_set("soap.wsdl_cache_enabled", "0");
//require_once realpath(APPLICATION_PATH . '/../library/').'/UserClass.php';
class Authentification {
/**
*
* @param string $username
* @param string $password
* @return string
*/
public function authentification($username,$password) {
$dbAdapter = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
$authAdapter->setTableName('standard_users')
->setIdentityColumn('username')
->setCredentialColumn('password');
$authAdapter->setIdentity($username);
$authAdapter->setCredential($password);
//authentification
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
//Authentification Réussie : on stocke les informations de l'utilisateur sauf le mot de passe !
$user = $authAdapter->getResultRowObject();
$UserName = $auth->getIdentity();
}
else $UserName = 'Authentication failed (Unknown user or incorrect password)! Please Retry !';
return $UserName;
}
}
?>
我的问题是当我写
$authAdapter->setIdentity($username);
$authAdapter->setCredential($password);
我在函数“身份验证”的原型中传递参数,Web 服务不起作用
但是当我直接设置参数时
$authAdapter->setIdentity('username');
$authAdapter->setCredential('password');
这行得通。
我不明白为什么参数不从函数“身份验证”的原型传递到 setIdentity 和 setCredential。
如果你能帮助我,我将不胜感激