Yet another problem with PHP soapclient, I hope someone can show me the correct way of doing this:
Here is a portion of the parameter array to keep things simple:
$params = array ( 'communication' => [ 'user-configuration' => [ 'ruleset' => [ 'rule' => [ '_' => '', 'id' => '999', 'conditions' => [ 'rule1' => 'true', ], 'actions' => [ 'forward-to' => [ 'target' => '123456' ], ], ], ], ], ], ); I call the soapclient as follows:
$client = new SoapClient ($wsdl, array( 'location' => "http://$ip:8080/CAI3G1.2/services/CAI3G1.2", 'uri' => "http://$ip:8080/CAI3G1.2/services/CAI3G1.2", 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE, 'connection_timeout' => 5, 'trace' => 1, 'encoding'=>' UTF-8' )); $header = new SoapHeader('http://schemas.ericsson.com/cai3g1.2/','SessionId',$sessionID,false); $client->__setSoapHeaders($header); try { $response = $client->Set($params); } catch(Exception $e){ if ($debug) print_r($e); return $e; } return $response; The XML generated has an extra unwanted part highlighted as follows:
<ns2:communication> <ns2:user-configuration> <ns2:ruleset> <ns2:rule id="999"> <ns2:id>999</ns2:id> <ns2:conditions> <ns2:rule1>true</ns2:rule1> </ns2:conditions> <ns2:actions> <ns2:forward-to> <ns2:target>123456</ns2:target> </ns2:forward-to> </ns2:actions> </ns2:rule> </ns2:ruleset> </ns2:user-configuration> </ns2:communication> the server doesnt like these extra line added on the request:
<ns2:id>999</ns2:id> if I put the same request on soapUI the request does not contain this extra values, it is as follows, which the server accepts:
<ns2:communication> <ns2:user-configuration> <ns2:ruleset> <ns2:rule id="999"> <ns2:conditions> <ns2:rule1>true</ns2:rule1> </ns2:conditions> <ns2:actions> <ns2:forward-to> <ns2:target>123456</ns2:target> </ns2:forward-to> </ns2:actions> </ns2:rule> </ns2:ruleset> </ns2:user-configuration> </ns2:communication> UPDATE: based on suggestions here, I also tried first building the XML and then convert to array as follows:
$xml_string= '<communication> <user-configuration> <ruleset> <rule id="999"> <conditions> <rule1>true</rule1> </conditions> <actions> <forward-to> <target>123456</target> </forward-to> </actions> </rule> </ruleset> </user-configuration> </communication>'; $xml_array = simplexml_load_string($xml_string); which gives the following array:
[user-configuration] => SimpleXMLElement Object ( [ruleset] => SimpleXMLElement Object ( [rule] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 999 ) [conditions] => SimpleXMLElement Object ( [rule1] => true ) [actions] => SimpleXMLElement Object ( [forward-to] => SimpleXMLElement Object ( [target] => 123456 ) ) ) ) ) but when using this array, the <rule> section is not even present in the request sent to the server.
@attributeskey as was proposed?@attributeskey doesn't work, here is another question that may help: stackoverflow.com/questions/1403628/…