Question

I'm using PHP SOAPSERVER class.

As a response I'm sending associative php array:

function getItems()    
{    
   ...
   $items[] = Array("itemID" =>$itemID,"itemName"=>$itemName);
   return $items;
 }

SOAP return is like this:

...
<Items>
<item type="Map">
    <item>
        <key type="string">
            itemID
        </key>
        <value type="string">
            17558
        </value>
    </item>
    <item>
        <key type="string">
            itemName
        </key>
        <value type="string">
            I-17558
        </value>
    </item>
</item>
</Items>
...

Such return is pretty hard to analyze for human (given bigger array). The preferred form would be like this:

    ...
<Items>
    <item>
        <itemID>17558</itemID>
        <itemName>I-17558</itemName>
    </item>
    <item>
        <itemID>17559</itemID>
        <itemName>I-17559</itemName>
    </item>
</Items>
    ...

Is such SOAP return possible (not changing the return type - array)? How?

I have just started with SOAP and most tutorials show how to return simple types like string.

Was it helpful?

Solution

Instead of sending an associative array, send a stdclass object.

Example :

$return = new stdclass;
$return->ItemID = 1;
$return->ItemName = 'foo';

return $return;

Then the SOAP results will be just the way you want it!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top