我正在使用Zend框架,我需要使用Zend_Soap制作web服务。在寻找了3天之后,我决定问自己。创建Zend_Soap_Server后,我得到消息
<SOAP-ENV ..>
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>sender</faultcode>
<faultstring>Invalid XML</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV>
然后我尝试了这个解决方案,我通过使用Zend_Soap_AutoDiscover让XML工作,但是当我尝试连接Zend_Soap_Client…
<?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Soap_Client');
$options = array(
'location' => 'http://zend/service/soap',
'uri' => 'http://zend/service/soap'
);
try {
$client = new Zend_Soap_Client(null, $options);
$foo = $client->foo();
var_dump($foo);
} catch (Exception $e) {
die($e->getMessage());
}
我得到的响应是
看起来没有XML文档
服务器上的代码(没有使用$soap,因为我无法让它工作):
public function soapAction() {
$this->_helper->layout()->disableLayout();
$this->getHelper('viewRenderer')->setNoRender(true);
$soap = new Zend_Soap_Server(null,array(
'uri' => 'http://zend/service/soap'
));
$soap->setClass('API_SoapFunctions');
$soap->setUri('http://zend/service/soap');
$autodiscover = new Zend_Soap_AutoDiscover();
$autodiscover->setClass('API_SoapFunctions')->setBindingStyle(array('style' => 'document'))->setUri('http://zend/service/soap');
header('Content-type: application/xml');
echo $autodiscover->toXml();
//$soap->handle();
}
在你的控制器中试试这个方法:
if(check if you have a request for WSDL){
$server = new Zend_Soap_AutoDiscover('Zend_Soap_Wsdl_Strategy_ArrayOfTypeComplex');
}else{
$server = new Zend_Soap_Server('URI_HERE');
}
$server->setClass('WS_CLASS_HERE');
$server->handle();