问题描述
在创建服务端"方面,我对Soap来说还比较陌生,因此请事先为我想使用的任何术语提供应用程序.
I'm relatively new to Soap on the "creating the service side", so appologies in advance for any terminology I'm munging.
是否可以从使用PHP的SoapServer类设置的远程过程肥皂服务中返回PHP数组?
Is it possible to return a PHP array from a Remote Procedure Soap Service that's been setup using PHP's SoapServer Class?
我有一个WSDL(盲目地按照教程构建),部分看起来像这样
I have a WSDL (built by blindly following a tutorial) that, in part, looks something like this
<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,看起来像这样
The PHP method I'm calling is named query, and looks something like this
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数组/集合.如果我更改查询方法以返回数组
I want to return a native PHP array/collection from my query method. If I change my query method to return an array
public function query($arg) {
$object = array('test','again');
return $object;
}
它在客户端被序列化为一个对象.
It's serialized into an object on the client side.
object(stdClass)[2]
public 'item' =>
array
0 => string 'test' (length=4)
1 => string 'again' (length=5)
这很有意义,因为我在WSDL中将xsd:object
指定为Result类型.如果可能的话,我想返回未包装在Object中的本机PHP数组.我的直觉说,有一个特定的xsd:type可以让我完成此操作,但我不知道.我还要解决被序列化为ArrayObject
的对象.
This makes sense, as I've specific a xsd:object
as the Result type in my WSDL. I'd like to, if possible, return an native PHP array that's not wrapped in an Object. My instincts say there's a specific xsd:type that will let me accomplish this, but I don't know. I'd also settle for the object being serialized as an ArrayObject
.
不要在WSDL的技术细节上教育我.我正在尝试了解
Don't hold back on schooling me in the technical details os WSDL. I'm trying to get a grasp on the underlying concepts fo
推荐答案
我使用了此WSDL生成器来创建描述文件.
I used this WSDL generator to create description file.
返回字符串数组是我的Web服务所做的事情,这是WSDL的一部分:
Returning array of strings is something what my web service does, here's part of WSDL:
<wsdl:types>
<xsd:schema targetNamespace="http://schema.example.com">
<xsd:complexType name="stringArray">
<xsd:complexContent>
<xsd:restriction base="SOAP-ENC:Array">
<xsd:attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="xsd:string[]" />
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<message name="notifyRequest">
<part name="parameters" type="xsd:string" />
</message>
<message name="notifyResponse">
<part name="notifyReturn" type="tns:stringArray" />
</message>
然后定义API函数notify
:
<wsdl:operation name="notify">
<wsdl:input message="tns:notifyRequest" />
<wsdl:output message="tns:notifyResponse" />
</wsdl:operation>
这篇关于从PHP SoapServer返回PHP数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!