[英]SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://127.0.0.1/test/index?wsdl' :
我在 zend framework 2.0 中使用 SOAP 組件時遇到問題
以下是代碼:
namespace User\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Soap\Server;
use Zend\Soap\Client;
use Zend\Soap\AutoDiscover;
use User\Model\MyTest;
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('User\Model\MyTest')
->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('User\Model\MyTest');
$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 錯誤:解析 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:\WWW\vendor\ZF2\library\Zend\Soap\Client.php:1087
Message:
Wrong Version
Stack trace:
#0 E:\WWW\vendor\ZF2\library\Zend\Soap\Client.php(1087): SoapClient->__soapCall('getUser', Array, NULL, NULL, Array)
#1 E:\WWW\module\User\src\User\Controller\TestController.php(44): Zend\Soap\Client->__call('getUser', Array)
這是 MyTest.php 文件
namespace User\Model;
class MyTest{
/**
* To get the register information of the user
*
* @return string
*/
public function getUser(){
return 'hello';
}
}
提前致謝。
要創建 Soap 服務器,您只需要 WSDL 文件,而不需要用於將其提供給其他客戶端的 URL。 事實上,最好不要為此使用 URL,因為對 Soap 服務器的每個請求都會啟動一個子請求來獲取 WSDL。
嘗試在創建 WSDL 后將其放在某處,並在后續請求中從那里獲取它。 每次自動檢測它只在沒有指定接口的情況下進行開發時才有用。 一旦其他人使用此接口並依賴其穩定性,這將破壞事情。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.