How to send an array of complex type in PHP using Soap_Client?

Posted by xaguilars on Stack Overflow See other posts from Stack Overflow or by xaguilars
Published on 2010-04-09T15:20:28Z Indexed on 2010/04/09 15:23 UTC
Read the original article Hit count: 271

Filed under:
|
|
|

Hello I want to know how to send this array of complex data to a SOAP server (that uses .NET / IIS).

    <xs:complexType name="SampleStruct">
        <xs:sequence>
            <xs:element name="title" type="xs:string"/>
            <xs:element name="description" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>   

     <xs:complexType name="SampleStruct_Array">
          <xs:complexContent>
           <xs:restriction base="soapenc:Array">
             <xs:sequence/>
             <xs:attribute ref="soapenc:arrayType" n1:arrayType="ns1:SampleStruct[]"/>
           </xs:restriction>
          </xs:complexContent>
        </xs:complexType>

Would this code be ok? :

$data1 = new SampleStruct();
$data1->title="Hello world";
$data1->description="This is a sample description.";

$data2 = new SampleStruct();
$data2->title="Hello world 2";
$data2->description="This is a sample description 2.";

$client->__soapCall("sampleFunction", array(
   new SoapParam(new SoapVar(array($data1, $data2) , SOAP_ENC_ARRAY, "SampleStruct_Array", "http://www.w3.org/2001/XMLSchema"), "theSampleFunctionParamName")
));

Am I doing it ok? I'm not very familiar with Web services...

Thank you

© Stack Overflow or respective owner

Related posts about php

Related posts about web-services