I'm developing a web service in PHP with NUSOAP and i have found the way to return an array. But what i'm trying to do his to return an array with array within. Example of array that i'm trying to return :
$return = array(
'lastName' => "Dupond",
'firstName' => array("Bryan", "Michael"),
'nationality' => "NA",
'gender' => "M"
);
Actually when i return this array i'm getting "unable to serialize result" error. I know for sure that it's because it don't understand the array in firstName.
What my code actually look like :
function hello($name, $firstname)
{
$lastName = "Name";
$firstName = array("firstName1","firstName2");
$nationality = "NA";
$gender = "M";
$return= array(
'lastName' => $lastName,
'firstName' => $firstName,
'nationality' => $nationality,
'gender' => $gender
);
return $return;
}
$server = new soap_server();
$server->configureWSDL("CallHello", "urn:CallHello");
$server->wsdl->addComplexType(
'Game', // the type's name
'complexType',
'struct',
'all',
'',
array(
'lastName' => array('name'=>'test','type'=>'xsd:string'),
'firstName' => array('name'=>'test','type'=>'tns:test'),
'nationality' => array('name'=>'test','type'=>'xsd:string'),
'gender' => array('name'=>'test','type'=>'xsd:string'),
)
);
$server->wsdl->addComplexType(
'test', // the type's name
'complexType',
'struct',
'all',
'',
array(
array('name'=>'firtsname1','type'=>'xsd:string'),
array('name'=>'firstname2','type'=>'xsd:string')
)
);
$server->wsdl->addComplexType(
'Games',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array(
'ref'=>'SOAP-ENC:arrayType',
'wsdl:arrayType'=>'tns:Game[]'
)
),
'tns:Game'
);
$server->register("hello",
array("name" => "xsd:string","firstname" => "xsd:xml"),
array("return" => "tns:Game"),
"urn:CallHello",
"urn:CallHello#hello",
"rpc",
"encoded",
"Get a Person Data");
//$server->service('php://input');
$server->service($HTTP_RAW_POST_DATA);
This what the concerned part of my wsdl look like :
<xsd:complexType name="Game">
<xsd:all>
<xsd:element name="lastName" type="xsd:string"/>
<xsd:element name="firstName" type="tns:test"/>
<xsd:element name="nationality" type="xsd:string"/>
<xsd:element name="gender" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
And what i want it too look like :
<xsd:complexType name="Game">
<xsd:all>
<xsd:element name="lastName" type="xsd:string"/>
<xsd:complexType name="firstName">
<xsd:all>
<xsd:element name="firstName1" type="xsd:string"/>
<xsd:element name="firstName2" type="xsd:string"/>
</xsd:all>
</xsd:complexType>
<xsd:element name="nationality" type="xsd:string"/>
<xsd:element name="gender" type="xsd:string"/>
</xsd:all>
</xsd:complexType>