Codice PHP:
// Pull in the NuSOAP code
require_once( "/lib/nusoap/lib/nusoap.php");
// Create the server instance
$server = new soap_server();
// Initialize WSDL support
$server->configureWSDL('WebService', 'urn:WebService');
// Register the data structures used by the service
// Registro una Anagrafica
$server->wsdl->addComplexType(
'DatoAnagrafico',
'complexType',
'struct',
'all',
'',
array(
'cognome' => array('name' => 'cognome', 'type' => 'xsd:string', 'lenght' => 15),
'nome' => array('name' => 'nome', 'type' => 'xsd:string', 'lenght' => 15),
'sesso' => array('name' => '', 'type' => 'xsd:string', 'lenght' => 1),
)
);
// Registro un blocco di inforamzioni (array di Anagrafiche piu' altri dati)
$server->wsdl->addComplexType(
'Elementi',
'complexType',
'struct',
'all',
'',
array(
'debug' => array('name' => '', 'type' => 'xsd:int', 'lenght' => 1),
'ID_Rif' => array('name' => '', 'type' => 'xsd:string', 'lenght' => 30),
'password' => array('name' => '', 'type' => 'xsd:string', 'lenght' => 2),
'Anagrafiche' => array('name'=>'DatiAnagrafici', 'maxOccurs'=>"6", 'minOccurs'=>"1", 'nillable'=>"false", 'type'=>'tns: DatoAnagrafico'), // OCio, tra tns: e il nome non ci va lo spazio, l'ho messo perchè sennò viene convertito nello smile!
)
);
$server->wsdl->addComplexType(
'Risultato',
'complexType',
'struct',
'all',
'',
array(
'esito' => array('name' => 'esito', 'type' => 'xsd:string'),
'messaggio' => array('name' => 'messaggio', 'type' => 'xsd:string'),
'debug' => array('name' => 'debug', 'type' => 'xsd:string')
)
);
// Register the methods to expose
$server->register('function_name', // method name
array('Elementi' => 'tns:Elementi'), // input parameters
array('Return' => 'tns:Risultato'), // output parameters
'urn:WebService', // namespace
'urn:WebService#function_name', // soapaction
'rpc', // style
'encoded', // use
"Testo di documentazione" // documentation
);
function function_name($elementi) {
bla bla bla
return array(
'esito' => $result->esito,
'messaggio' => $result->messaggio,
'debug' => $result->debug,
);
}
$server->service($HTTP_RAW_POST_DATA);
A sto punto quindi il test viene piuttosto semplice (o almeno...dovrebbe!)