I've a wsdl file with this complexType:
I write this function to convert above object to an associative array:
<complexType name="ArrayOfString">On my soap client I call soap server in this manner:
<complexContent>
<restriction base="soapenc:Array">
<attribute ref="soapenc:arrayType"
wsdl:arrayType="string[]"/>
</restriction>
</complexContent>
</complexType>
$client = new SoapClient('marco.wsdl', array('trace' => 1,'encoding'=>'ISO-8859-1'));My server function log this request:
$data['user']['usr_id'] = 8;
$data['user']['username'] = 'marco';
$data['event'] = 'delete';
$result = $client->__soapCall('notify', array($data));
SoapServer->notify: stdClass::__set_state(array(Php map my complexType to an object!
'item' =>
array (
0 =>
stdClass::__set_state(array(
'key' => 'user',
'value' =>
stdClass::__set_state(array(
'item' =>
array (
0 =>
stdClass::__set_state(array(
'key' => 'usr_id',
'value' => '8',
)),
1 =>
stdClass::__set_state(array(
'key' => 'username',
'value' => 'marco',
)),
),
)),
)),
1 =>
stdClass::__set_state(array(
'key' => 'event',
'value' => 'delete',
)),
),
))
I write this function to convert above object to an associative array:
function getArrayFromXSDObject($map) {And now the log output is:
if( !isset($map->item) || empty($map->item) )
return array();
$ary = array();
foreach($map->item as $obj) {
if(is_object($obj->value)) {
$ary[$obj->key] = $this->getArrayFromXSDObject($obj->value);
} else {
$ary[$obj->key] = $obj->value;
}
}
return $ary;
}
array (PS: if you want a very good library to handle SOAP and WSDL try to look at NuSOAP or any other, but NOT soap php module!
'user' =>
array (
'usr_id' => '8',
'username' => 'marco',
),
'event' => 'delete',
Commenti
Posta un commento