【问题标题】:NuSoap - Nested Array in addComplexType are allowed ?NuSoap - addComplexType 中的嵌套数组是否允许?
【发布时间】:2014-09-18 22:30:27
【问题描述】:

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

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

$server->wsdl->addComplexType( '姓名', '复杂类型', '结构', '全部', '', 数组(数组( 'code' => array('name' => 'code', 'type' => 'xsd:string'), 'product' => array('name' => 'product', 'type' => 'xsd:string'), 'level' => array('name' => 'level', 'type' => 'xsd:float') )) ); $server->register('updateCode', // 方法名 array('name' => 'tns:name'), // 输入参数 array('return' => 'xsd:string'), // 输出参数 'urn:updateCode', // 命名空间 'urn:updatecode#updateCode', // 肥皂动作 'rpc', // 样式 '编码' // 使用 ); 函数更新代码($输入){ 返回计数($输入); }

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

我不明白为什么会这样。

谢谢,

【问题讨论】:

    标签: php xml nusoap


    【解决方案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'
    );
    

    第二个有参数“元素”:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-02
      • 2016-02-11
      • 2010-11-21
      • 1970-01-01
      • 2013-09-10
      • 1970-01-01
      • 2012-04-10
      • 2017-07-18
      相关资源
      最近更新 更多