5

I used the SoapClient Library to get data from TecDoc webservices. All of the ws functions work except this special function whose parameter 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 goal of the above function is to get all product's information from their id (array of ids).

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)

The other functions that I don't have to pass an array parameter to a property work perfectly.

I found out that 'array' => array(361024, 365118) causes the error. If I let the array be NULL, the above code works, just returns empty result (because no product ids are passed).

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

An example of functions that works well:

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 an array), NuSOAP can execute the first codes successfully, return right result. But NuSOAP causes too many troubles especially slow speed. We are forced to use SoapClient.

So I guess that NuSOAP library has somewhere convert all child array to suitable format but SoapClient doesn't. Tried some solutions but no luck. Please help me to solve this.

3 Answers 3

4
+50

The "Known Compatibility Problems" section of the "TecDoc WebService Interface description" document at page 5 states:

PHP does not implement different integer data types. Depending on the operating system an integer contains 32 or 64 bit. Therefore an automatic implicit mapping from int (32 bit) to long (64 bit) is done on discrete parameters which take a 64 bit value. However, this does not work with arrays, so there functions having arrays of strings containing the numeric values have to be used.

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

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

1 Comment

You are right about the function that should be used. Tecdoc should have provided some examples of a simple PHP implementation(at least I couldn't find any). This part of the documentation looks way clearer with the important parts in bold.
1

A SoapVar should be used, so the request can be properly handled. Some pieces from the 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));

It's not for the same function, but I hope it helps.

Comments

1

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

'features' => SOAP_USE_XSI_ARRAY_TYPE

to SoapClient constructor.

I hope this is going to resolve problems for others.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.