note 54955 added to ref.soap
| From: | Darryl at osu1 dot php dot net | Date: | Wed, 20 Jul 2005 18:46:05 +0000 |
| Subject: | note 54955 added to ref.soap | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92223@lists.php.net to get a copy of this message | ||
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
}
?>
----
Manual Page -- http://www.php.net/manual/en/ref.soap.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54955
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54955&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54955&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54955&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54955&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54955&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54955&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54955&report=yes
Search -- http://master.php.net/manage/user-notes.php