关于zend_soap如何来进行web service就不多说了
详见http://www.cnblogs.com/zcy_soft/archive/2011/01/10/1932177.html
参考代码:http://download.csdn.net/source/2967369
这个帖子重点讲讲如何用 zend_soap 框架来进行用户验证
必要前提懂的参考代码中的内容
原理:客户端访问服务器,首先发出soapheader信息,先进行验证,如果soapheader中的内容是正确的,
那么将会改变服务器端改成已经授权,否则就跑出错误
考代代码
客户端SoapController.php 访问地址:http://test.localhost:8080/soap/client
注意:发送的SoapHeader里面,
"userConfirmation" :接受soapheader并处理的方法
array("test","888888") :给处理soapheader方法的两个参数
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
$client = new Zend_Soap_Client("http://tools.localhost:8080/soapserver/index?wsdl");
$soapUri = $this->_WSDL_URI;
$client->addSoapInputHeader(
new SoapHeader(
$soapUri,
"userConfirmation",
array("test","888888")
)
);
$xmlConente = file_get_contents('C:\TestPhp\public\t3.xml');
echo $client->SyncCrawlerCV($xmlConente);die;
服务器端 SoapserverController.php wsdl访问地址:http://tools.localhost:8080/soapserver/index?wsdl
注意:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
private function handleWSDL() {
$autodiscover = new Zend_Soap_AutoDiscover();
//类名要注意一致
$autodiscover->setClass('Dhr_SoapService');
$autodiscover->handle();
}
private function handleSOAP() {
$soap = new Zend_Soap_Server('http://tools.localhost:8080/soapserver/index?wsdl');
$soap->setClass('Dhr_SoapService');
$soap->handle();
}
public function indexAction() {
//判断请求中是否有wsdl有就自动生成wsdl的uri否则启动soap服务
if (isset($_GET['wsdl'])) {
$this->handleWSDL();
} else {
$this->handleSOAP();
}
}
服务器端关键代码
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
class Dhr_SoapService {
public $authorized = false;
//other param
/**
* a main function can be sync crawler cv
* @param string $XMLString
* @return string
*/
public function SyncCrawlerCV($XMLString) {
$this->xmlMessageObj = new xmlMessage();
if(!$this->authorized){
$this->xmlMessageObj->createSon('exceptions', 'No login!');
return $this->xmlMessageObj->getXML();
}
//do something
}
/**
* method for user comfirmaation
* @param string $userInfo
*/
public function userConfirmation($userName, $passWord){
if($userName =='test' && $passWord == '888888'){
$this->authorized = true;
}
}
//other function s
}