gpt4 book ai didi

php - NuSoap - 允许在 addComplexType 中嵌套数组?

转载 作者:数据小太阳 更新时间:2023-10-29 02:45:07 25 4
gpt4 key购买 nike

我需要从客户端接收这样的 XML 输入(包含 2 个或更多元素):

<list>
<item>
<code xsi:type="xsd:string">123</code>
<product xsi:type="xsd:string">hello</product>
<level xsi:type="xsd:float">3</level>
</item>

<item>
<code xsi:type="xsd:string">1234</code>
<product xsi:type="xsd:string">hello2</product>
<level xsi:type="xsd:float">4</level>
</item>
</list>

我可以定义一个这样的复杂类型来描述服务方法的输入参数吗(使用数组(数组(...)?

     $server->wsdl->addComplexType(       'name',       'complexType',       'struct',       'all',       '',        array (array (          'code' => array('name' => 'code', 'type' => 'xsd:string'),          'product' => array('name' => 'product', 'type' => 'xsd:string'),          'level' => array('name' => 'level', 'type' => 'xsd:float')      ))    );
    $server->register('updateCode',                    // method name             array('name' => 'tns:name'),          // input parameters             array('return' => 'xsd:string'),    // output parameters             'urn:updateCode',                         // namespace             'urn:updatecode#updateCode',                   // soapaction             'rpc',                                    // style             'encoded'                                // use    );    function updateCode($input){            return count($input);    }

当我使用包含 2 个项目的 XML 时,我获得 2 个作为响应;当我使用只有 1 个项目的 XML 时,我得到 3 个作为响应(就像每个项目的字段数),而我期望结果为 1 个。

我不明白为什么会这样。

谢谢,

最佳答案

问题有点老,但我正在处理一些遗留肥皂服务并遇到了它。

这个 SO 答案可能会有所帮助:https://stackoverflow.com/a/1505720/1666805

问题 1)您需要声明 2 个复杂类型,其中第一个是“列表”:

$soap->wsdl->addComplexType(
'list',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(
'list' => array(
'name' => 'list', 'type' => 'tls:item'
)
),
array(
array(
'ref'=>'tns:item',
'wsdl:arrayType'=>'tns:item[]'
)
),
'tns:item'
);

第二个参数为“element”:

$soap->wsdl->addComplexType(
'item',
'element',
'struct',
'all',
'',
array(
'code' => array('name' => 'code', 'type' => 'xsd:string'),
'product' => array('name' => 'product', 'type' => 'xsd:string'),
'level' => array('name' => 'level', 'type' => 'xsd:float')
)
);

从这里开始,使用上面的列表类型作为输入来注册函数应该很容易。

问题 2)我会查看传递给函数的实际数组而不是计数:

array(1) {
'item' =>
array(2) {
[0] =>
array(3) {
'code' =>
string(3) "123"
'product' =>
string(5) "hello"
'level' =>
double(3)
}
[1] =>
array(3) {
'code' =>
string(4) "1234"
'product' =>
string(6) "hello2"
'level' =>
double(4)
}
}
}

关于php - NuSoap - 允许在 addComplexType 中嵌套数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24983337/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com