views:

444

answers:

1

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

EDITED:

I've got the solution. PHP SOAP extension is more easy to use that I was thinking...

I've just passed the complex data structures as associative arrays with no problem.

Example:

$client->someServerFunction("value1", array(array("title"=>"title1", "description"=>"description1"), array("title"=>"title2", "description"=>"description2")));
A: 

Answered here - http://stackoverflow.com/questions/577795/passing-array-to-soap-function-in-php

Ivo Sabev
Hi Ivo, sorry but my question was not answered there...
xaguilars
The source code you posted looks okay to me is it working or producing any error?
Ivo Sabev
the ASP.NET server seems that doesn't like those parameters... perhaps I need to serialize the array? I don't know... I'm lost :(
xaguilars