0

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.

4
  • Why do you want to read the SOAP messages at all? Usually the client converts it into whatever native structures/types fit the response's data. Commented Jun 25, 2012 at 12:18
  • @ThiefMaster, I want to parse SOAP message as a XML using DOM methods. It looks quite messy with the current response message structure. Commented Jun 25, 2012 at 13:06
  • Ugh, use an existing SOAP client... anyway, that's how SOAP looks like. You cannot simply use a different format. It's standardized. Commented Jun 25, 2012 at 13:07
  • @ThiefMaster, thanks for the info. Thoughts of being able to change that structure was killing me. Commented Jun 25, 2012 at 14:09

1 Answer 1

5

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!

Sign up to request clarification or add additional context in comments.

1 Comment

The SOAP Client uses object notation when sending objects, so this should answer the OP's question. You can also instantiate the predefined class by using typical object instantiation syntax, ie "new stdClass()".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.