PHP/Soap not possible to return a complex type or array??

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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

<s:complexContent><s:restriction base="SOAP-ENC:Array"><s:attribute

Actual Output :

object(stdClass)#2 (1) { ["item"]=>  object(stdClass)#3 (2) {
["key"]=>  string(1) "c" ["value"]=>  string(1) "3" } }


"a" => "1" and "b" => "2" elements are missing, but "c" => "3" is

Client.php ===
  $client = new SoapClient("http://localhost:84/server.wsdl");
  $test = $client->getList();

Server.php ====
function getList() {  
    return array("a" => 1,"b" => 2,"c" => 3);  // the array we're
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("server.wsdl");

server.wsdl ===
<?xml version="1.0" encoding="UTF-8"?>
<y:definitions xmlns:http=" /"
xmlns:soap=" /"
xmlns:s=" "
xmlns:s0=" :84/soap/"
xmlns:soapenc=" /"
xmlns:mime=" /"
xmlns=" /"
xmlns:y=" /"
xmlns:xsd=" "
xmlns:SOAP-ENV=" /"
xmlns:SOAP-ENC=" /"
xmlns:wsdl=" /"
xmlns:ns=" :84/soap/"
targetNamespace=" :84/soap/">
        <s:schema targetNameSpace=" :84/soap/"
            <s:complexType name="getListArray">
                    <s:restriction base="SOAP-ENC:Array">
                        <s:attribute ref="SOAP-ENC:arrayType"
    <y:message name="getListSoapOut">
        <part name="parameter" type="y:getListArray"/>
    <portType name="SoapPortType">
        <operation name="getList">
            <output message="s0:getListSoapOut"/>
    <y:binding name="SoapBinding" type="s0:SoapPortType">
        <soap:binding style="rpc"
transport=" "/>
        <y:operation name="getList">
            <soap:operation soapAction="urn:#getList" style="rpc"/>
                <soap:body use="literal"/>
    <service name="SoapService">
        <port name="SoapPort" binding="s0:SoapBinding">
            <soap:address location=" :84/server.php?wsdl"/>

Re: PHP/Soap not possible to return a complex type or array??

burdeen wrote in message
Quoted text here. Click to load it

So, I've solved my own problem... I believe it was the fault of the
WSDL, maybe PHP/Soap is sensitive to my weird namespaces.  The thing
that helped the most was the PHP/Soap unit tests; i was able to write
a wsdl that was able to get the results i wanted. take a look here:

Hopefully this will help someone else. There is very little (or no?)
documents yet on how to return complex types from the server... so
here is an example. Server will return an array of strings to the
client as SOAP-ENC:arrayType string[].

client2.php ===

  $client = new SoapClient("http://localhost:84/server2.wsdl",
  $test = $client->test();

server2.php ===


function test() {  
    return array("ham","cheese","bacon");

ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$server = new SoapServer("server2.wsdl");


server2.wsdl ===

<wsdl:definitions xmlns:xsd=" "
xmlns:SOAP-ENC=" /"
xmlns:soap=" /"
xmlns:wsdl=" /"
xmlns=" /"
xmlns:ns=" /"
xmlns:ns1=" /"
targetNamespace="http://test-uri/" name="InteropTest">
        <schema xmlns=" "
            <xsd:import namespace=" /"/>
            <xsd:import namespace=" /"/>
            <complexType name="testType">
                    <restriction base="SOAP-ENC:Array">
                        <attribute ref="SOAP-ENC:arrayType" wsdl:arrayType="string[]"/>
    <message name="testMessage">
        <part name="testParam" type="tns:testType"/>
    <portType name="testPortType">
        <operation name="test">
            <output message="tns:testMessage"/>
    <binding name="testBinding" type="tns:testPortType">
        <soap:binding style="rpc"
transport=" "/>
        <operation name="test">
            <soap:operation soapAction="test" style="document"/>
                <soap:body parts="body" use="literal"
encodingStyle=" /"
    <service name="testService">
        <port name="testPort" binding="tns:testBinding">
            <soap:address location="http://localhost:84/server2.php?wsdl"/>

Re: PHP/Soap not possible to return a complex type or array??

burdeen wrote:
Quoted text here. Click to load it

Good research, perhaps you could add an example to the documentation page.


Site Timeline