NuSOAP and response with Array

本秂侑毒 提交于 2019-12-06 05:37:18

问题


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.


回答1:


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.




回答2:


I solve the problem doing this in the v1.123 2010/04/26 20:15:08 nusoap lib.

Comment the Line 6136:

$contents .= $this->serializeType('item', $typeDef['arrayType'], $v, $use);

And add this code:

$tag = end( explode(":" , $typeDef['arrayType'] ));
$tag = $tag==""?'item':$tag;
$contents .= $this->serializeType( $tag, $typeDef['arrayType'], $v, $use);

Works for me ! Hope helps !



来源:https://stackoverflow.com/questions/974139/nusoap-and-response-with-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!