Reputation: 3965
I'm trying to make a soap request and the method I'm calling takes any number of objects define by this:
<xs:complexType name="thing">
<xs:sequence>
<xs:element minOccurs="0" name="string1" type="xs:string"/>
<xs:element minOccurs="0" name="string2" type="xs:string"/>
<xs:element minOccurs="0" name="string3" type="xs:long"/>
</xs:sequence>
</xs:complexType>
How do I create an object like that in PHP and pass it to the soap method? Right now the (not working) code I have looks like this:
$obj->string1 = 'something';
$obj->string2 = 'something';
$obj->string3 = 'something';
$param = new SoapParam(new SoapVar($obj, SOAP_ENC_OBJECT, 'method', 'http://ns'), 'paramName');
$soapClient->method($param);
UPDATE:
This is the body of the request of the shown method:
<SOAP-ENV:Body>
<ns2:method xsi:type="ns1:method">
<string1>something</string1>
<string2>something</string2>
<string3>something</string3>
</ns2:placeHolds>
</SOAP-ENV:Body>
If I just pass $obj instead of creating a SoapParam, this is the body in the request:
<SOAP-ENV:Body>
<ns1:method/>
</SOAP-ENV:Body>
Upvotes: 2
Views: 7588
Reputation: 2143
$client = new SoapClient('endpoint');
$sequence->string1 = 'something';
$sequence->string2 = 'something';
$sequence->string3 = 'something';
$obj = array();
$obj['sequence'] = $sequence;
$param = new SoapParam(new SoapVar($obj, SOAP_ENC_OBJECT), 'paramName');
$client->__soapCall('method',array($param));
Upvotes: 1