Re: nested object in SOAP result

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7 September 2010 19:12, nik600 <nik600@gmail.com> wrote:
> Dear all
>
> i'm trying to retrieve an array of ElementB objects into the ElementA
> element, but the array is incapsulated into a Struct object, how can i
> avoid that and have directly the array result?
>
> This is the var_dump output of my result
>
> object(GetElementResponse)#2 (1) {
>  ["Element"]=>
>  object(stdClass)#3 (2) {
>    ["PropertyA1"]=>
>    string(4) "test"
>    ["Elements"]=>
>    object(stdClass)#4 (1) {
>      ["Struct"]=>
>      array(2) {
>        [0]=>
>        object(stdClass)#5 (1) {
>          ["PropertyB1"]=>
>          string(7) "test B1"
>        }
>        [1]=>
>        object(stdClass)#6 (1) {
>          ["PropertyB1"]=>
>          string(7) "test B2"
>        }
>      }
>    }
>  }
> }
>
>  this is the code on server-side:
> <?php
> class testelementwsserver{
>
>        function __construct(){
>
>        }
>
>        function GetElement(){
>
>                $GetElementResponse = new GetElementResponse();
>                $GetElementResponse->Element = new ElementA();
>                $GetElementResponse->Element->PropertyA1="test";
>
>
>                $e1=new ElementB();
>                $e1->PropertyB1="test B1";
>
>                $e2=new ElementB();
>                $e2->PropertyB1="test B2";
>
>                $GetElementResponse->Element->Elements=array($e1,$e2);
>
>                return $GetElementResponse;
>        }
>
> }
>
> $server = new SoapServer("http://localhost/prove_php/test-ws/test.wsdl";);
> $server->setClass("testelementwsserver");
> $server->handle();
>
> ?>
>
> and this is my WSDL file:
>
>      <xsd:element name="GetElement">
>        <xsd:complexType>
>          <xsd:sequence>
>          </xsd:sequence>
>        </xsd:complexType>
>      </xsd:element>
>
>      <xsd:element name="GetElementResponse">
>        <xsd:complexType>
>          <xsd:sequence>
>            <xsd:element name="Element" type="xsd:ElementA" />
>          </xsd:sequence>
>        </xsd:complexType>
>      </xsd:element>
>
>      <xsd:element name="ElementA">
>      <xsd:complexType>
>        <xsd:sequence>
>          <xsd:element maxOccurs="1" minOccurs="0" name="PropertyA1"
> type="xsd:string" />
>          <xsd:element maxOccurs="1" minOccurs="0" name="Elements"
> type="xsd:ElementB" />
>        </xsd:sequence>
>      </xsd:complexType>
>      </xsd:element>
>
>      <xsd:element name="ElementB">
>      <xsd:complexType>
>        <xsd:sequence>
>          <xsd:element maxOccurs="1" minOccurs="0" name="PropertyB1"
> type="xsd:string" />
>        </xsd:sequence>
>      </xsd:complexType>
>      </xsd:element>
>
> Thanks to all in advance
>
> --
> /*************/
> nik600
> http://www.kumbe.it
>
> --
> PHP Soap Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

I use a tool to convert a WSDL file into a bunch of PHP classes, so
that I can use these classes in a normal way when I get my results.

Essentially, I don't do an SOAP calls directly or any XML processing.
I'm only using the SOAPClient class (and SOAPHeader if required) that
are native to PHP, but wrapped to be useful for the service.

If you can send me the wsdl file, I'll send you back the classes you need.

Whilst it is entirely possible to do all of this without a wsdl2php
script, and do it all in XML, it just seems a little harder. Why
bother when you can use OOP classes and have all the XML/SOAP/WSDL
wrapped up and hidden away.

Richard.

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
PHP Soap Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [PHP Users]     [Kernel Newbies]     [PHP Database]     [Yosemite]

  Powered by Linux