views:

95

answers:

1

I want to make a call to a webservice of which I only have the WSDL file. I'll list the important bits from the WSDL file with context sensitive names replaced by general ones:

The function I want to call:

<wsdl:operation name="myFunction">
   <wsdl:input message="ns:myFunctionRequest" wsaw:Action="urn:myFunction"/>
   <wsdl:output message="ns:myFunctionResponse" wsaw:Action="urn:myFunctionResponse"/>
</wsdl:operation>

The description of the function:

<xs:element name="myFunction">
   <xs:complexType>
      <xs:sequence>
         <xs:element minOccurs="0" name="param0" nillable="true" type="xs:string"/>
         <xs:element minOccurs="0" name="param1" nillable="true" type="somens:MyType"/>
         <xs:element minOccurs="0" name="param2" nillable="true" type="xs:string"/>
      </xs:sequence>
   </xs:complexType>
</xs:element>

The description of 'MyType':

<xs:complexType name="MyType">
    <xs:sequence>
        <xs:element minOccurs="0" name="date1" nillable="true" type="xs:dateTime"/>
        <xs:element minOccurs="0" name="date2" nillable="true" type="xs:dateTime"/>
        <xs:element minOccurs="0" name="string1" nillable="true" type="xs:string"/>
        <xs:element minOccurs="0" name="int1" nillable="true" type="xs:int"/>
        <xs:element minOccurs="0" name="int2" nillable="true" type="xs:int"/>
    </xs:sequence>
</xs:complexType>

I am thinking of my PHP code looking a bit like this:

$client = new SOAPClient('my soap URL');

$result = $client->setState(array('param0'=>'bla', 'param1'=><undecided>, 'param2'=>'bla');

My problem is what to put in the undecided part. Should that be an array that maps names in the complex type to values? Or should it be a class that I define myself with field of the corresponding types? I don't have a good testing ground to try this out at this moment and I would like to be able to move on before I do have it available.

I saw a lot of SOAP related questions unanswered, so I hope I will get lucky :). If I happen to find out myself, I will of course share my results.

Thanks in advance!

+1  A: 

In my experience, you need an object instead of an array, but stdClass will suffice, so you can just cast an array to object if it makes life easier:

$client->myFunction(
    'bla',
    (object)array(
        'date1'   => '2010-01-01 00:00:00',
        'date2'   => '2010-01-02 00:00:00',
        'string1' => 'foobar',
        'int1'    => 1,
        'int2'    => 2
    ),
    'bla');
Wrikken
Thanks! That's very concise and to the point. Exactly what I needed. I'll make another comment here to confirm that it worked when I have to ability to test it.
Matthijs Wessels
I tested it and it worked.
Matthijs Wessels
Goed om the horen )
Wrikken