首先新建一个服务端wsdl文件类
<?php
class Model_Service_SoapClassSetTest {
public
function getUser($a,$b) {
return
array("test"=>array(12345,"唐先生"),$b=>array('a'=>$a));
}
public
function getPass($a,$b) {
return (object)array($a,$b);
}
}
注意注释部分的写法:一定是/** 开头 @param为接收参数的描述,@return为返回值的结构类类描述。
for example :
@param和@return的值类型如下:
PHP strings
<->
xsd:string.
PHP integers
<-> xsd:int.
PHP floats and doubles
<->
xsd:float.
PHP booleans
<->
xsd:boolean.
PHP arrays
<->
soap-enc:Array.
PHP object
<->
xsd:struct.
PHP class <-> based on complex type strategy PHP void <-> empty type.
If type is not matched to any of these
types by some reason, then xsd:anyType is
used.
新建Controller文件:
<?php
class
Soap_server_test {
function indexAction(){
if(isset($_GET['wsdl']))
{
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('Model_Service_SoapClassSetTest');
$autodiscover->handle();
} else {
// pointing to the current file here
$soap = new Zend_Soap_Server("http://tj.test.com/default/soap_server_test/index?wsdl");
$soap->setClass('Model_Service_SoapClassSetTest');
$soap->handle();
}
}
function clientAction() {
$options= array('encoding'
=> 'UTF-8','compression' =>
SOAP_COMPRESSION_ACCEPT );
$client = new
Zend_Soap_Client('http://tj.test.com/default/soap_server_test/index?wsdl',$options);
$result=$client->getUser(array("tang"),"man");
print_r($result);
$result=$client->getPass("tang","man");
print_r($result);
}
}
其中$soap->setClass('Model_Service_SoapClassSetTest');中的Model_Service_SoapClassSetTest 是刚才新建的类名。