擴充soap api的任務,除了要更新wsdl文件,還要記得把Server跟Client Cache都必須清理掉纔會正常,不然site會看到類似的信息
PHP Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Server] Procedure 'your_func' not present
以下是片段代碼:
//Client
//清除client的soap Cache
ini_set("soap.wsdl_cache_enabled","0");
$soapclient = new SoapClient($syncUrl);
//或者直接再實例化Client的時候帶參數
$soapclient = new SoapClient($syncUrl,array('cache_wsdl' => WSDL_CACHE_NONE));
$array = $soapclient->__getTypes();
$functions = $soapclient->__getFunctions();
print_r($functions);
$var["a"] = "1";
$var["b"] = "2";
echo $soapclient->add(2,8)."\n";
//Server
ini_set("soap.wsdl_cache_enabled","0");
$server = new SoapServer($wsdlFilePos, array('soap_version' => SOAP_1_2)); ##此處的wsdl文件是上面生成的
$server->setClass("soapHandle"); //註冊soapHandle類的所有方法
$server->handle(); //處理請求