Search code examples
phpweb-servicessoapwsdl

Sending PHP array via SOAP - mysterious bug?


I have one really weird problem with PHP, SOAP and XSD sequence types.

I have this type definition is WSDL:

<xsd:complexType name="ArrayOfLong">
    <xsd:sequence>
        <xsd:element name="item" type="xsd:long" minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
</xsd:complexType>

And I use this function to create an object for the ArrayOfLong structure:

function packArray($array) {
    $packed = new stdClass();
    $packed->item = $array;
    return $packed;
}

I'm calling this SOAP method:

<xsd:element name="DoGetPostBuyFormsDataForSellersRequest">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element name="sessionId" type="xsd:string"/>
            <xsd:element name="transactionsIdsArray" type="tns:ArrayOfLong" minOccurs="0"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>

... with PHP code that looks pretty much like this:

$transactions = array( /* here are some numbers */ );
$soapClient = new SoapClient( /* here is the WSDL URL */ );
$soapClient->__soapCall("doGetPostBuyFormsDataForSellers", array(array(
    "sessionId" => $mySessionId,
    "transactionsIdsArray" => packArray($transactions)
)));

The problem: The array is sometimes converted to array containing only element with value of 1. I don't really know why, if it depends on the values or on the length of the array or anything else...

Here is a correct SOAP request (called with [0] => 317989652 [1] => 318208647):

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://webapi.aukro.cz/service.php">
    <SOAP-ENV:Body>
        <ns1:DoGetPostBuyFormsDataForSellersRequest>
            <ns1:sessionId>*****</ns1:sessionId>
            <ns1:transactionsIdsArray>
                <ns1:item>317989652</ns1:item>
                <ns1:item>318208647</ns1:item>
            </ns1:transactionsIdsArray>
        </ns1:DoGetPostBuyFormsDataForSellersRequest>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

And here is a wrong one, produced by the same code, but with different $transactions array: [0] => 316828610 [1] => 316909581 [2] => 317077717 [4] => 317077835 [5] => 317134572 [6] => 317493491 [7] => 317676419 [8] => 317713706 [9] => 317894940 [10] => 317909359 [12] => 317989652 [13] => 318208647

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://webapi.aukro.cz/service.php">
    <SOAP-ENV:Body>
        <ns1:DoGetPostBuyFormsDataForSellersRequest>
            <ns1:sessionId>*****</ns1:sessionId>
            <ns1:transactionsIdsArray>
                <ns1:item>1</ns1:item>
            </ns1:transactionsIdsArray>
        </ns1:DoGetPostBuyFormsDataForSellersRequest>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Does anybody know what can be causing this problem? Thanks.


Solution

  • So I solved the problem... There were some missing elements (gaps) in the array and it seems that SoapClient can't handle this.