问题
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