Zend Framework 2 モジュールで SOAP サーバーを動作させることができません。完全にはわかりませんが、問題は WSDL ファイルにあると思います。Zend Framework によって提供される Autodiscover を介して WSDL ファイルを作成しようとしました。error.log は次のとおりです。
[Fri Apr 19 20:39:29 2013] [error] [client 172.23.31.109] PHP Warning: SoapServer::SoapServer(): I/O warning : failed to load external entity "http-LINK/services?wsdl" in /PATH/public_html/vendor/zendframework/zendframework/library/Zend/Soap/Server.php on line 749
[Fri Apr 19 20:39:29 2013] [error] [client 172.23.31.109] PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http-LINK/services?wsdl' : failed to load external entity "http-LINK/services?wsdl"\n in /PATH/public_html/vendor/zendframework/zendframework/library/Zend/Soap/Server.php on line 749
このサービス テスト用に独自のモジュールを追加しました。これが構造で、モジュールは「サービス」と呼ばれます。
-Services
--config
---module.config.php
--src
---Services
----API
-----1.0
------servicesAPI.php
---Controller
----ServicesController.php
--view
---services
----serivces
-Module.php
-autoload_classmap.php
これは私のファイル「servicesAPI.php」です
class servicesAPI {
/**
* This method takes a value and gives back the md5 hash of the value
*
* @param String $value
* @return String
*/
public function md5Value($value) {
return md5($value);
}
}
これは ServicesController.php です。
namespace Services\Controller;
ini_set("soap.wsdl_cache_enabled", 0);
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Soap\AutoDiscover;
use Zend\Soap\Server;
require_once __DIR__ . '/../API/1.0/servicesAPI.php';
class ServicesController extends AbstractActionController {
private $_options;
private $_URI = "http-LINK/services";
private $_WSDL_URI = "http-LINK/services?wsdl";
public function indexAction() {
if (isset($_GET['wsdl'])) {
$this->handleWSDL();
} else {
$this->handleSOAP();
}
}
private function handleWSDL() {
$autodiscover = new AutoDiscover();
$autodiscover->setClass('servicesAPI')
->setUri($this->_URI);
$autodiscover->handle();
}
private function handleSOAP() {
$soap = new Server($this->_WSDL_URI);
$soap->setClass('servicesAPI');
$soap->handle();
}
}
これをデプロイしてブラウザで http-LINK/services を開くと、次のようになります。
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>WSDL</faultcode>
<faultstring>
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http-LINK/services?wsdl' : failed to load external entity "http-LINK/services?wsdl"
</faultstring>
<detail/>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
この呼び出しでは、PHP エラー出力も書き込まれます。ブラウザで services?wsdl を開こうとすると、次のように表示されます (chrome と safari):
This page contains the following errors:
error on line 3 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.
This method takes a value and gives back the md5 hash of the value
しかし、要素を調べると、完全に問題ないように見えます。
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http-LINK/services" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap-enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" name="servicesAPI" targetNamespace="http-LINK/services"><types><xsd:schema targetNamespace="http-LINK/services"/></types><portType name="servicesAPIPort"><operation name="md5Value"><documentation>This method takes a value and gives back the md5 hash of the value</documentation><input message="tns:md5ValueIn"/><output message="tns:md5ValueOut"/></operation></portType><binding name="servicesAPIBinding" type="tns:servicesAPIPort"><soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/><operation name="md5Value"><soap:operation soapAction="http-LINK/services#md5Value"/><input><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http-LINK/services"/></input><output><soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http-LINK/services"/></output></operation></binding><service name="servicesAPIService"><port name="servicesAPIPort" binding="tns:servicesAPIBinding"><soap:address location="http-LINK/services"/></port></service><message name="md5ValueIn"><part name="value" type="xsd:string"/></message><message name="md5ValueOut"><part name="return" type="xsd:string"/></message></definitions>
この xml は任意の xml バリデーターで検証できますが、有効なようです。
これに関するすべての投稿をstackoverflowで読み、Googleを検索しましたが、解決策はどれも役に立ちませんでした。他に試したことの短いリストを次に示します。
- これによると: https://bugs.php.net/bug.php?id=48216 wsdl xml をファイルに保存し、soap サーバーの起動時にこのファイルから開こうとしましたが、失敗しました
- 例外をキャッチするために、try/catch を使用して autodiscover ステートメントと soapserver ステートメントを実行しようとしましたが、何も表示されません。
- toXML() およびその他の出力を介してエコーを試みましたが、失敗しました
- XMLReader::open と isValid を使用して、xml が有効であることを確認しました (有効です)。
いくつかの詳細情報:
- PHP バージョン 5.3.23
- Ubuntu サーバー 11.04
- php-soap モジュールがロードされます
- Zend フレームワーク バージョン 2.1.4
ヘルプやヒントをいただければ幸いです。前もって感謝します。