ConFoo Montreal 2026: Call for Papers

Voting

: four minus two?
(Example: nine)

The Note You're Voting On

Darryl
20 years ago
Having trouble passing complex types over SOAP using a PHP SoapServer in WSDL mode? Not getting decoded properly? This may be the solution you're looking for!

When using ComplexType in the schema portion of the WSDL file, You need use an additional step to tell PHP SOAP how to encode the objects. The first method would be to explicitely encapsulate the object in a SoapVar object - telling PHP to use generalized SOAP encoding rules (which encodes all ComplexTypes as Structs). This won't work, though, if the client is expecting the objects to be encoded according to the WSDL's schema. So, The actual way to do this is:

* First, define a specific PHP class which is actually just a data structure holding the various properties, and the appropriate ComplexType in the WSDL.

<?php
class MyComplexDataType {
public
$myProperty1;
public
$myProperty2;
}
?>
<complexType name="MyWSDLStructure">
<sequence>
<element name="MyProperty1" type="xsd:integer"/>
<element name="MyProperty2" type="xsd:string"/>
</sequence>
</complexType>

* Next, Tell the SoapServer when you initialize it to map these two structures together.

<?php
$classmap
= array('MyWSDLStructure' => 'MyComplexDataType');
$server = new SoapServer("http://MyServer/MyService.wsdl", array('classmap' => $classmap))
?>

* Finally, have your method return an instance of your class directly, and let the SoapServer take care of encoding!

<?php
public function MySoapCall() {
$o = new MyComplexDataType();

$o->myProperty1 = 1;
$o->myProperty2 = "MyString";

return
$o
}
?>

<< Back to user notes page

To Top