NuSOAP and response with Array

Alexey picture Alexey · Jun 10, 2009 · Viewed 14.5k times · Source

I've NuSOAP web-server: ...

    $server->register('getMembersEvents',       
        array('date' => 'xsd:string'),                      
        array('Events' => 'tns:Events'),
        'urn:my',             
        false,                          
        'rpc',                          
        false,                          
        'Description'               
    );

    $server->wsdl->addComplexType(
        'Events',
        'complexType',
        'array',
        '',
        'SOAP-ENC:Array',
        array('Event' =>array ('name' => 'Event', 'type' => 'tns:Event')),
        array(
            'Event' => array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Event[]')
        ),
        'tns:Event'
    );

$server->wsdl->addComplexType(
    'Event',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'field1' => array('name' => 'MemberNumber', 'type' => 'xsd:int'),
                 // ...
        'fieldN' => array('name' => 'WebMemberID', 'type' => 'xsd:int')
    )
);

Everyting works fine, but the response seems like:

<SOAP-ENV:Body>
  <ns1:getMembersEventsResponse xmlns:ns1="urn:eliza">
         <Events xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:Event[2]">
            <item xsi:type="tns:Event">
               <field1 xsi:type="xsd:int">123</field1>
                  ...
               <fieldN xsi:type="xsd:int">123</fieldN>
            </item>
            <item xsi:type="tns:Event">
               <field1 xsi:type="xsd:int">123</field1>
                  ...
               <fieldN xsi:type="xsd:int">123</fieldN>
            </item>
         </Events>
      </ns1:getMembersEventsResponse>
   </SOAP-ENV:Body>

How cab I rename "item"? I have to have Events -> Event node structure.

Answer

Elhussein Hashem picture Elhussein Hashem · Oct 1, 2009

I solved this problem using this

$server->wsdl->addComplexType(
'Event',
'element',
'struct',
'all',
'',
array(
    'field1' => array('name' => 'MemberNumber', 'type' => 'xsd:int'),
             // ...
    'fieldN' => array('name' => 'WebMemberID', 'type' => 'xsd:int')
));

I use "element" instead of "complexType" for the typeClass parameter.