I've been trying to return an array with PHP5 soap. Is this not
supported? or am i doing it wrong? Seems to return on the last element
in the array. In my WSDL i've defined my return type as a complex
type:
<s:complexContent><s:restriction base="SOAP-ENC:Array"><s:attribute
ref="SOAP-ENC:arrayType"
wsdl:arrayType="xsd:string[]"/></s:complexContent>
Actual Output :
object(stdClass)#2 (1) { ["item"]=> object(stdClass)#3 (2) {
["key"]=> string(1) "c" ["value"]=> string(1) "3" } }
Expected:
"a" => "1" and "b" => "2" elements are missing, but "c" => "3" is
there.
Client.php ===
<?php
$client = new SoapClient("http://localhost:84/server.wsdl");
$test = $client->getList();
print(var_dump($test));
?>
Server.php ====
<?php
function getList() {
return array("a" => 1,"b" => 2,"c" => 3); // the array we're
returning
}
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("server.wsdl");
$server->addFunction("getList");
$server->handle();
?>
server.wsdl ===
<?xml version="1.0" encoding="UTF-8"?>
<y:definitions xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:s0="http://10.1.1.151:84/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:y="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns="http://10.1.1.151:84/soap/"
targetNamespace="http://10.1.1.151:84/soap/">
<y:types>
<s:schema targetNameSpace="http://10.1.1.151:84/soap/"
elementFormDefault="qualified">
<s:complexType name="getListArray">
<s:complexContent>
<s:restriction base="SOAP-ENC:Array">
<s:attribute ref="SOAP-ENC:arrayType"
wsdl:arrayType="xsd:string[]"/>
</s:restriction>
</s:complexContent>
</s:complexType>
</s:schema>
</y:types>
<y:message name="getListSoapOut">
<part name="parameter" type="y:getListArray"/>
</y:message>
<portType name="SoapPortType">
<operation name="getList">
<output message="s0:getListSoapOut"/>
</operation>
</portType>
<y:binding name="SoapBinding" type="s0:SoapPortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
<y:operation name="getList">
<soap:operation soapAction="urn:#getList" style="rpc"/>
<output>
<soap:body use="literal"/>
</output>
</y:operation>
</y:binding>
<service name="SoapService">
<port name="SoapPort" binding="s0:SoapBinding">
<soap:address location="http://10.1.1.151:84/server.php?wsdl"/>
</port>
</service>
</y:definitions>