Question

I am using PHP 5.2.10 and I am trying to consume a webservice which returns complex data types using the standard SOAP extension.

The problem is that SoapClient does not populate objects which are nested into other objects / array of objects. A simplified example of what I get when I call the getUtente method, specifying "my_unique_id" as a parameter is:

stdClass Object
(
    [getUtenteReturn] => stdClass Object
        (
            [userName] => my_unique_id
            [fieldOne] => ...
            [fieldTwo] => ...
            [utilizzatore] => stdClass Object
                ( // This is EMPTY instead of containing a series of userName's
                )

        )

)

The relevant part of the WDSL description is:

<element name="getUtenteResponse">
  <complexType>
    <sequence>
      <element name="getUtenteReturn" type="tns1:Cliente"/>
    </sequence>
  </complexType>
</element>
...
<complexType name="Utilizzatore">
  <sequence>
    <element name="userName" nillable="true" type="xsd:string"/>
  </sequence>
</complexType>
...
<complexType name="Cliente">
  <complexContent>
    <extension base="tns1:Utilizzatore">
      <sequence> 
        <element name="fieldOne" nillable="true" type="xsd:string"/>
        <element name="fieldTwo" nillable="true" type="xsd:string"/>
        <element name="utilizzatore" nillable="true" type="impl:ArrayOf_tns1_Utilizzatore"/>
      </sequence>
    </extension>
  </complexContent>
</complexType>

What I found I am not the only one experiencing this problem. In particular I found this comment in the PHP official documentation and this other forum entry to give two different ideas on how to approach the problem, but I have not been able to turn any of those two ideas into a working solution: I seem not to completely understand the logic behind the examples given.

I would be grateful if anybody could guide me in this: some working code on another webservice would be welcome, but what I am primarily after is really understanding the problem and the logic of the solutions proposed (the fish lane, not the fish!). :)

Was it helpful?

Solution

Old question, no answer. I recently stumbled on this post, that explains the problem and gives a solution: Consuming SOAP complexType webservice with PHP.

OTHER TIPS

Here are my immediate thoughts, sorry this isn't a proper answer, just some ideas...

First, have you tried viewing the soap request (the envelope) sent to the soap server? Does it look like it should work? Can you see where it is going wrong? Are you just getting an error back, a soapFault, or the wrong data, or nothing at all?

Second, have you tried using the SoapParam class?

Finally, I'm sure you're doing this right, but I notice that the object you are building has username and fieldOne and fieldTwo all side by side, but your WSDL shows that fieldOne and fieldTwo are part of the class Cliente (which never shows up in your example) while username should be inside of the utilizzatore array, so shouldn't it be more like:

stdClass Object
(
    [Cliente] => stdClass Object
        (
            [fieldOne] => ...
            [fieldTwo] => ...
            [utilizzatore] => stdClass Object
                ( // This is EMPTY instead of containing a series of userName's
                )

        )

)

The SoapClient class is very frustrating for me to, so don't take any of this as a criticism, because I only hope to better understand it myself by offering up ideas that might help you.

Mac, thanks a lot for your prompt responses. look at what i tumbled on.. I did not look at this earlier. Hence want to share this.

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