NuSoap - 允许使用addComplexType中的嵌套数组?

[英]NuSoap - Nested Array in addComplexType are allowed ?


I need to receive from client an XML input like this (with 2 or more elements):

我需要从客户端接收这样的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>

May I define a complexType like this to describe input parameter for service method (using an array(array(...)?

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

     $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);
    }

When I use an XML with 2 items, I obtain 2 as response; when I use an XML with only 1 item, I obtain 3 as response (LIKE THE NUMBER OF THE FIELDS OF EACH ITEM), where I expected 1 as result.

当我使用带有2个项目的XML时,我得到2作为响应;当我使用只有1个项目的XML时,我得到3作为响应(就像每个项目的字段数一样),我预期结果为1。

I don't understand why this occurs.

我不明白为什么会这样。

Thanks,

谢谢,

1 个解决方案

#1


0  

Question is a little old, but I was working on some legacy soap services and came across it.

问题有点旧,但我正在研究一些传统的肥皂服务并遇到过它。

This SO answer will likely help: https://stackoverflow.com/a/1505720/1666805

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

Question 1) You need to declare 2 complex types where the first is the "list":

问题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'
);

And the second having the argument "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')
    )
);

From here, it should be easy enough to register the function using the list type above as input.

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

Question 2) I would look at the actual array being passed to the function instead of the count:

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

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)
    }
  }
}
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2014/07/27/7df2db8302a1f073783f3e8b439d7ccc.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告