1

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.

5
  • Once again, you want to set an attribute on a particular node - how is this any different from your previous question, stackoverflow.com/a/79652281/1427878 ? Commented Jun 5 at 6:16
  • 1
    This is different, I am following up the recommendations of stackoverflow.com/a/79652281/1427878 (which actually fixed my previous issue), but in this case the produced XML contains an extra line, duplicating the "id" and causing the server to reject it. To clarify, the output XML should contain: <ns2:rule id="999"> but instead is getting: <ns2:rule id="999"> <ns2:id>999</ns2:id> Causing the server to reject because of "id" being duplicated. Commented Jun 5 at 6:39
  • @Diego But if you followed the answer, why isn't the array (here in that new question) containing an @attributes key as was proposed? Commented Jun 5 at 6:55
  • In case the @attributes key doesn't work, here is another question that may help: stackoverflow.com/questions/1403628/… Commented Jun 5 at 7:31
  • hi @GuillaumeOutters, if you look on top of the case, it shows the case where a similar answer was posted and resolved, I followed that one which was to add the '_' => '', part, this fixed my previous problem :) Commented Jun 5 at 7:32

1 Answer 1

0

Many thanks for the pointers provided here, they did point me in the right direction.

After trying several attempts in building the proper parameters array, I gave up on that approach, so I started playing with XMLwriter as suggested on another post, I could not make it to work either as soapClient requires a conversion to array which is not clean.

I found the best approach for me in this post:

Issue with sending SOAP request, through soapclient, to service that expects CDATA

I completely removed soapClient and used Guzzle instead, at the end it is a lot easier as I can just grab the XML text file I build from SOAPUI and send it directly.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.