从PHP SoapServer返回PHP数组
发布时间:2020-12-13 21:34:52 所属栏目:PHP教程 来源:网络整理
导读:我对Soap在“创建服务方面”方面比较陌生,所以请提前预测我正在修改的任何术语. 是否可以从使用PHP的SoapServer类设置的远程过程肥皂服务返回PHP数组? 我有一个WSDL(盲目地按照教程建立),部分看起来像这样 message name='genericString' part name='Result'
我对Soap在“创建服务方面”方面比较陌生,所以请提前预测我正在修改的任何术语.
是否可以从使用PHP的SoapServer类设置的远程过程肥皂服务返回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方法是命名查询,看起来像这样 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) 这是有道理的,因为我在我的WSDL中将xsd:object特定为Result类型.如果可能的话,我想返回一个未包含在Object中的本机PHP数组.我的直觉说有一个特定的xsd:类型可以让我实现这个目标,但我不知道.我还决定将被序列化为ArrayObject的对象. 不要在WSDL的技术细节中拒绝接受我的教育.我正在努力掌握基本概念 解决方法
我使用
this WSDL generator来创建描述文件.
返回字符串数组是我的Web服务所做的事情,这是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> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |