简体   繁体   English

通过SOAP发送PHP数组-神秘的错误?

[英]Sending PHP array via SOAP - mysterious bug?

I have one really weird problem with PHP, SOAP and XSD sequence types. 我对PHP,SOAP和XSD序列类型有一个非常奇怪的问题。

I have this type definition is WSDL: 我有这个类型定义是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: 我使用此函数为ArrayOfLong结构创建一个对象:

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

I'm calling this SOAP method: 我正在调用此SOAP方法:

<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: ...看起来像这样的PHP代码:

$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 . 问题:有时将数组转换为仅包含值为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 ): 这是一个正确的SOAP请求(用[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 这是一个错误的错误,由相同的代码产生,但是具有不同的$transactions数组: [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. 谢谢。

因此,我解决了问题...数组中缺少一些元素(间隙),似乎SoapClient无法处理此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM