PHP soapClient和Sequences问题

时间:2013-04-29 22:14:09

标签: php soap

我在这里阅读了一些其他解决方案,看似与我遇到的问题类似的问题,但似乎都没有。无论如何,我需要调用一个soap函数,该函数具有与其父元素同名的元素序列,并且所有名称都具有'。'在他们中。下面是wsdl的一部分,我似乎无法绕过一种创建类似于所需内容的数组的方式。

此外,'option.list'的子数组总是会有不同的出现次数,所以我需要在php中使用某种循环来构建它。非常感谢任何帮助。

<xs:element minOccurs="0" name="option.list">
<xs:complexType>
    <xs:complexContent>
        <xs:extension base="cmn:ArrayType">
            <xs:sequence>
                <xs:element maxOccurs="unbounded" minOccurs="0" name="option.list">
                    <xs:complexType>
                        <xs:complexContent>
                            <xs:extension base="cmn:StructureType">
                                <xs:sequence>
                                    <xs:element minOccurs="0" name="SubItemId" nillable="true" type="cmn:DecimalType"/>
                                    <xs:element minOccurs="0" name="SubOptions" nillable="true" type="cmn:StringType"/>
                                    <xs:element minOccurs="0" name="SubItemName" nillable="true" type="cmn:StringType"/>
                                </xs:sequence>
                            </xs:extension>
                        </xs:complexContent>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:extension>
    </xs:complexContent>
</xs:complexType>
</xs:element>

我尝试过的想法:

for($i=0;$i<count($options);$i++)
{
    $option_list[] = array(
      "option.list" => array(
      "SubItemId" => $i,
      "SubOptions" => $options[$i]['suboptions'],
      "SubItemName" => $options[$i]['subitemname']
      )
);
}

$instance = array(
    "option.list"=>$option_list
);

当我调试请求时,它会一直显示我正在发送的内容:

<ns1:option.list><ns1:option.list/></ns1:option.list>

另外,这就是我发送之前print_r时option.list数组的样子,如果这有帮助的话。

                [option.list] => Array
                    (
                        [0] => stdClass Object
                            (
                                [option.list] => stdClass Object
                                    (
                                        [SubItemId] => 0
                                        [SubOptions] => <?xml version="1.0" encoding="UTF-8" standalone="yes"?><form><select id="DBMS" label="DBMS type:" style="combo">MS SQL<option label="" /><option id="0" label="DB2">DB2</option><option id="1" label="IMS">IMS</option><option id="2" label="MS SQL">MS SQL</option><option id="3" label="Oracle">Oracle</option><option id="4" label="UDB">UDB</option></select><select id="Type" label="lation Type:" style="combo">Add New Instance<option label="" /><option id="0" label="Add New Environment">Add New Environment</option><option id="1" label="Add New Instance">Add New Instance</option><option id="2" label="Add New Database">Add New Database</option><option id="3" label="Modify Environment">Modify Environment</option><option id="4" label="Modify Instance">Modify Instance</option><option id="5" label="Modify Database">Modify Database</option><option id="6" label="Retire Environment">Retire Environment</option><option id="7" label="Retire Instance">Retire Instance</option><option id="8" label="Retire Database">Retire Database</option></select><select id="Complexity" label="xity:" style="combo">Complex [+$2500.00]<option label="" /><option id="0" label="Simple [+$500.00]">Simple [+$500.00]</option><option id="1" label="Medium [+$1000.00]">Medium [+$1000.00]</option><option id="2" label="Complex [+$2500.00]">Complex [+$2500.00]</option></select><select id="RecoveryTier" label="rability Tier:" style="combo">Tier 2<option label="" /><option id="0" label="Tier 1">Tier 1</option><option id="1" label="Tier 2">Tier 2</option><option id="2" label="Tier 3">Tier 3</option></select><select id="Backup" label=" Backup Required?" style="combo">Yes<option label="" /><option id="0" label="Yes">Yes</option><option id="1" label="No">No</option></select><select id="Replication" label=" tables require replication?" style="combo">UDB Dprop<option label="" /><option id="0" label="UDB Dprop">UDB Dprop</option><option id="1" label="Goldengate">Goldengate</option><option id="2" label="ASM">ASM</option><option id="3" label="No">No</option></select></form>
                                        [SubItemName] => DB Modification
                                    )

                            )

                    )

2 个答案:

答案 0 :(得分:2)

我实际上从来没有弄清楚如何从对象或数组中获取所需的soapEnvelope。但作为一种功能性的解决方法,我能够继承SoapClient并覆盖__doRequest方法。这允许我发送我自己的原始xml请求,该请求现在正在运行。

我在此处找到了此解决方法:Sending Raw XML via PHP SoapClient request

答案 1 :(得分:0)

我建议使用以下代码,但我没有尝试:

for($i=0;$i<count($options);$i++) {
    $option_list[] = array(
       "SubItemId" => $i,
       "SubOptions" => $options[$i]['suboptions'],
       "SubItemName" => $options[$i]['subitemname']
    )
}

$instance = array(
    "option.list"=>$option_list
);

我认为您不需要创建具有键'option.list'的父数组。 名称'option.list'仅适用于wsdl类型引用本身,但根本不发送。 wsdl告诉你:'option.list'类型是关联数组的基数数组:

array(
    array(
        'SubItemId' => <DECIMAL>,
        'SubOptions' => '<STRING>',
        'SubItemName' => '<STRING>'
    ),
    array(
        'SubItemId' => <DECIMAL>,
        'SubOptions' => '<STRING>',
        'SubItemName' => '<STRING>'
    ),
    array(
        'SubItemId' => <DECIMAL>,
        'SubOptions' => '<STRING>',
        'SubItemName' => '<STRING>'
    ),
    ...,
    ...
)