我对 Soap 的“创建服务端”还比较陌生,所以提前对我正在思考的任何术语表示歉意。
是否可以从使用 PHP 的 SoapServer 类设置的远程过程 Soap 服务返回 PHP 数组?
我有一个 WSDL(通过盲目遵循教程构建),部分看起来像这样
<message name='genericString'>
<part name='Result' type='xsd:string'/>
</message>
<message name='genericObject'>
<part name='Result' type='xsd:object'/>
</message>
<portType name='FtaPortType'>
<operation name='query'>
<input message='tns:genericString'/>
<output message='tns:genericObject'/>
</operation>
</portType>
我调用的 PHP 方法名为 query,看起来像这样
public function query($arg){
$object = new stdClass();
$object->testing = $arg;
return $object;
}
这让我可以打电话
$client = new SoapClient("http://example.com/my.wsdl");
$result = $client->query('This is a test');
结果转储看起来像
object(stdClass)[2]
public 'result' => string 'This is a test' (length=18)
我想从我的查询方法返回一个本机 PHP 数组/集合。如果我更改查询方法以返回数组
public function query($arg) {
$object = array('test','again');
return $object;
}
它在客户端被序列化为一个对象。
object(stdClass)[2]
public 'item' =>
array
0 => string 'test' (length=4)
1 => string 'again' (length=5)
这是有道理的,因为我已经具体说明了xsd:object
作为我的 WSDL 中的结果类型。如果可能的话,我想返回一个未包装在对象中的本机 PHP 数组。我的直觉告诉我有一个特定的 xsd:type 可以让我完成此任务,但我不知道。我还决定将对象序列化为ArrayObject
.
请不要吝啬地教我 WSDL 的技术细节。我正在尝试掌握基本概念