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

注意!

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



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