给梦一个奔跑的方向!
PDF Print E-mail
User Rating: / 0
PoorBest 
Written by xlingfairy
Tuesday, 09 February 2010 17:42
仍然是困了我几天,没有解决.网上关于这方面的资料太少了.
不过,我还是找到了解决方法:
 
 
SOAP Server 声明:
 
ini_set ( "soap.wsdl_cache_enabled", "0" );
$soap = new Zend_Soap_Server ( URL . "/?wsdl" ); // this current file here
$soap->setClass ( 'Joomla_User' );
$soap->handle ();
 
 
Joomla_User 的声明:
<?php
class User{
/**
* @var string
*/
public $name;
/**
* @var string
*/
public $sex;
public function __construct($name , $sex){
$this->name = $name;
$this->sex = $sex;
}
}
 
class UserCollection{
/**
* @var User[]
*/
public $users = array();
}
 
class Joomla_User{
/**
* @param string $username
* @param string $password
*/
    public function UsernameToken( $username, $password ){
$f = fopen('a.txt','w+');
fwrite($f, $username);
fclose($f);
    }
/**
* @return User[]
*/
public static function ListUser(){
$users = array();
$users[] = new User('xling','male');
$users[] = new User('snow','female');
/* $uc = new UserCollection();
$uc->users = $users;*/
return $users;
}
/**
* @return string[]
*/
public static function GetUser(){
return array('xling','snow');
}
/**
* @return User
*/
public static function GetUser2(){
return new User('xling','male');
}
}
?>
 
 
 
客户端声明:
 
class SoapHeaderUsernameToken {
/** @var string Password */
public $Password;
/** @var string Username */
public $Username;
public function __construct($l, $p) {
$this->Password = $p;
$this->Username = $l;
}
}
 
 
$client = new Zend_Soap_Client('http://soap/index.php?wsdl');
$usernameToken = new SoapHeaderUsernameToken('xling','xlingfairy');
$soapHeader = new SoapHeader('http://schemas.xmlsoap.org/ws/2002/07/utility', 'UsernameToken', $usernameToken);
$client->addSoapInputHeader($soapHeader);
var_dump($client->GetUser2());
 
 
这样,当调用 $client->GetUser2() 之后,首先会调用 Joomla_User 类的 UsernameToken 方法.
这里只是个示例,证明一下而以.
 

Add comment


Security code
Refresh

Popular Contents

Recommend

Site Info

Members : 1
Content : 130
Web Links : 7
Content View Hits : 99664

Links