SOAP-ERROR:解析WSDL:无法从'http://127.0.0.1/test/index?wsdl'加载:
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SOAP-ERROR:解析WSDL:无法从'http://127.0.0.1/test/index?wsdl'加载:相关的知识,希望对你有一定的参考价值。
当我在zend framework 2.0中使用SOAP组件时遇到问题
以下是代码:
namespace UserController;
use ZendMvcControllerAbstractActionController;
use ZendSoapServer;
use ZendSoapClient;
use ZendSoapAutoDiscover;
use UserModelMyTest;
class TestController extends AbstractActionController {
private $_WSDL_URI = "http://127.0.0.1/test/index?wsdl";
private function handleWSDL() {
$autodiscover = new AutoDiscover();
//ini_set("soap.wsdl_cache_enabled", 0);
$autodiscover->setClass('UserModelMyTest')
->setUri($this->_WSDL_URI);
$wsdl = $autodiscover->generate();
header("Content-type: text/xml");
echo $wsdl->toXml();
exit;
}
private function handleSOAP() {
$soap = new Server($this->_WSDL_URI,array('encoding' => 'utf-8','soap_version'=>SOAP_1_2));
$soap->setClass('UserModelMyTest');
$soap->handle();
exit;
}
public function indexAction(){
if(isset($_GET['wsdl'])) {
$this->handleWSDL();
} else {
$this->handleSOAP();
}
}
public function clientAction(){
$client = new Client('http://127.0.0.1/test/index?wsdl');
$result = $client->getUser(31);
var_dump($result);exit;
}
}
当我访问http://localhost/test/index?wsdl
时,它返回WSDL。
但是当我访问http://localhost/test/index
时,它返回错误:
SOAP-ERROR:解析WSDL:无法从http://127.0.0.1/test/index?wsdl
加载:无法加载外部实体"http://127.0.0.1/test/index?wsdl"
当我访问http://localhost/test/client
时,它返回
An error occurred
An error occurred during execution; please try again later.
Additional information:
SoapFault
File:
E:WWWvendorF2libraryendSoapClient.php:1087
Message:
Wrong Version
Stack trace:
#0 E:WWWvendorF2libraryendSoapClient.php(1087): SoapClient->__soapCall('getUser', Array, NULL, NULL, Array)
#1 E:WWWmoduleUsersrcUserControllerTestController.php(44): ZendSoapClient->__call('getUser', Array)
这是MyTest.php文件
namespace UserModel;
class MyTest{
/**
* To get the register information of the user
*
* @return string
*/
public function getUser(){
return 'hello';
}
}
提前致谢。
答案
要创建Soap服务器,您只需要WSDL文件,而不是用于将其提供给其他客户端的URL。实际上,最好不要使用URL来执行此操作,因为对Soap服务器的每个请求都将启动子请求以获取WSDL。
尝试在创建WSDL后将其放在某处,并在后续请求中从那里获取它。在没有指定接口的情况下进行开发时,每次自动检测它都是很好的。一旦其他人使用这个界面并依赖其稳定性,这将破坏事情。
以上是关于SOAP-ERROR:解析WSDL:无法从'http://127.0.0.1/test/index?wsdl'加载:的主要内容,如果未能解决你的问题,请参考以下文章