PHP SoapClient "deserialize error" when passing array to array in property

I used the SoapClient library to retrieve data from TecDoc web services. All ws functions work, except for this special function, the parameter of which contains an array in an array .

Here is my code:

 $client = new SoapClient("http://webservice-cs.tecdoc.net/pegasus-2-0/wsdl", array("trace" => true)); //array of product ids $data = array( 'empty' => false, 'array' => array(361024, 365118), ); $params = array( 'provider' => 23014, 'lang' => 'es', 'country' => 'es', 'articleId' => $data, 'attributs' => true, 'documents' => true, 'documentsData' => false, 'eanNumbers' => false, 'immediateAttributs' => true, 'immediateInfo' => false, 'info' => true, 'prices' => false, 'priceDate' => null, 'normalAustauschPrice' => false, 'mainArticles' => false, 'oeNumbers' => true, 'replacedNumbers' => false, 'replacedByNumbers' => false, 'usageNumbers' => false, 'normalAustauschPrice' => false, ); $test = $client->__soapCall('getDirectArticlesByIds2', array('in0' => $params)); var_dump($test); 

The purpose of this function is to obtain all product information from its identifier (array of identifiers).

SoapClient shows the following error:

[soapenv:Server.userException] org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize. in C:\xampp 1.8.1\htdocs\www\test.php:59 Stack trace: #0 C:\xampp 1.8.1\htdocs\www\test.php(59): SoapClient->__soapCall('getDirectArticl...', Array)

Other functions that I do not need to pass to the array parameter in the property work fine.

I found that 'array' => array(361024, 365118) is causing an error. If I give the array NULL , then the above code works, it simply returns an empty result (because no product identifiers are passed).

 $data = array( 'empty' => false, 'array' => null, ); 

An example of well-functioning functions:

 static public function addDynamicIp($hour) { $client = new SoapClient("http://webservice-cs.tecdoc.net/pegasus-2-0/wsdl"); $params = array( 'provider' => 23014, 'address' => $_SERVER['REMOTE_ADDR'], 'validityHours' => $hour, ); $client->__soapCall('addDynamicAddress', array('in0' => $params)); } 

With the same parameters (contains an array in the array ), NuSOAP can successfully execute the first codes, return the correct result. But NuSOAP causes too many problems, especially slow speed. We are forced to use SoapClient.

So, I assume that the NuSOAP library somewhere converts the entire child array into a suitable format, but SoapClient does not. I tried some solutions, but no luck. Please help me solve this problem.

+4
source share
3 answers

The "Known Compatibility Issues" section of " TecDoc WebService Interface Description " on page 5 says:

PHP does not implement different integer data types. Depending on the operating system, the integer contains 32 or 64 bits. Therefore, automatic implicit matching from int (32 bits) to long (64 bits) is performed by discrete parameters that take a 64-bit value. However, this does not work with arrays , therefore there are functions that have arrays of strings containing numerical values ​​that should be used .

So, as far as I understand, it seems that with PHP you should use getDirectArticlesByIds2StringList instead of getDirectArticlesByIds2 .

+2
source

A SoapVar , so the request can be processed correctly. Some snippets from working code:

 class ArticleIdPair { public $articleId = null; public $articleLinkId = null; function __construct($articleId, $articleLinkId) { $this->articleId = $articleId; $this->articleLinkId = $articleLinkId; } } class ArticleIdPairSequence { public $array = array(); public $empty = true; function __construct(array $articleIdPairs) { $this->array = $articleIdPairs; if (count($articleIdPairs) > 0) { $this->empty = false; } } } //... $soapClient = new SoapClient(TECDOC_WEBSERVICE_WSDL_URL, array( "classmap" => array( "ArticleIdPair" => "ArticleIdPair", "ArticleIdPairSequence" => "ArticleIdPairSequence" ) )); //... $test = new ArticleIdPair($articleId, $articleLinkId); $articleIdPairSeq = new ArticleIdPairSequence(array($test)); $encodedPairSeq = new SoapVar($articleIdPairSeq, SOAP_ENC_OBJECT, "ArticleIdPairSequence"); $params = array( //... "articleIdPairs" => $encodedPairSeq, //... ); //... $result = $soapClient->__SoapCall("getAssignedArticlesByIds2", array($params)); 

This is not for the same function, but I hope this helps.

+1
source

Tried other answers with no luck. I had problems with the getAssignedArticlesByIds2 and ArticleIdPairSeq function. I solved the array problem by adding:

 'features' => SOAP_USE_XSI_ARRAY_TYPE 

to the SoapClient constructor .

I hope this solves the problems for others.

0
source

Source: https://habr.com/ru/post/1500881/


All Articles