Zend_Soap_Server
PHPでクラスを使用してSOAPサーバーを実装しようとしています。
webservice.php
リクエストのエントリポイントであるファイルは次のとおりです。
<?php
require_once 'library.php';
require_once 'Zend/Loader/Autoloader.php';
$autoloader = \Zend_Loader_Autoloader::getInstance();
class Math
{
/**
* This method takes ...
*
* @param integer $inputParam
* @return \Library\IncrementedInt
*/
public function increment($inputParam)
{
return new \Library\IncrementedInt($inputParam);
}
}
$options = array('uri' => 'http://localhost' . $_SERVER['REQUEST_URI']);
if (isset($_GET['wsdl'])){
$server = new Zend_Soap_AutoDiscover();
$server->setClass('Math');
}
else {
$server = new Zend_Soap_Server(null, $options);
$server->setClass('Math');
$server->setObject(new Math());
}
$server->handle();
そして、私はlibrary.php
次のようなファイルを持っています:
<?php
namespace Library;
class IncrementedInt
{
public $original;
public $incremented;
public function __construct($num)
{
$this->original = $num;
$this->incremented = ++$num;
}
}
を呼び出すと、次のhttp://localhost/webservice.php?wsdl
ように出力されます。
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://localhost/webservice.php" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 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="Math" targetNamespace="http://localhost/webservice.php">
<script/>
<types>
<xsd:schema targetNamespace="http://localhost/webservice.php">
<xsd:complexType name="\Library\IncrementedInt">
<xsd:all/>
</xsd:complexType>
</xsd:schema>
</types>
<portType name="MathPort">
<operation name="increment">
<documentation>This method takes ...</documentation>
<input message="tns:incrementIn"/>
<output message="tns:incrementOut"/>
</operation>
</portType>
<binding name="MathBinding" type="tns:MathPort">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="increment">
<soap:operation soapAction="http://localhost/webservice.php#increment"/>
<input>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/webservice.php"/>
</input>
<output>
<soap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://localhost/webservice.php"/>
</output>
</operation>
</binding>
<service name="MathService">
<port name="MathPort" binding="tns:MathBinding">
<soap:address location="http://localhost/webservice.php"/>
</port>
</service>
<message name="incrementIn">
<part name="inputParam" type="xsd:int"/>
</message>
<message name="incrementOut">
<part name="return" type="tns:\Library\IncrementedInt"/>
</message>
</definitions>
soapUI 4.5.1
ここで、SOAP クライアントを実装する Java アプリケーションである、使用する機能をテストします。URIを指定http://localhost/webservice.php?wsdl
すると関数increment
が抽出されるはずですが、そうではありません。代わりに、エラーが表示されます: The Value '\Library\IncrementInt' is an invalid name
. \
タイプ名の一部として受け入れるのに問題があるようです。一方、PHPはそれらなしではできません。
他のすべてが問題ないことを確認するために、名前空間なしでまったく同じファイルをテストしたところ、スムーズに動作しました.
誰かが同様の問題に直面したことがありますか?さらに重要なことに、この問題を克服する方法を知っている人はいますか?
[アップデート]
ZF2 で同じシナリオをテストすることができましたが、うまくいきました。ZF1は諦めなきゃいけないかも!