Código PHP:
# informa la conexion
require_once('includes/init.php');
# libreria nuSoap
require_once('classes/soap/nusoap.php');
$URL = 'http://localhost/';
$server = new soap_server();
$server->configureWSDL('ws_nombre', $URL);
$server->wsdl->schemaTargetNamespace=$URL;
$server->wsdl->addComplexType(
'Competitor',
'complexType',
'struct',
'all',
'',
array(
'ID_Competitor' => array('name'=>'ID_Competitor', 'type'=>'xsd:int'),
'Competitor' => array('name'=>'Competitor', 'type'=>'xsd:string')
)
);
$server->wsdl->addComplexType(
'Competitors',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Competitor[]')
),
'tns:Competitor'
);
/* competidores */
$server->register('getCompetitors', // Nombre de la funcion
array(), // Parametros de entrada
array('return' => 'tns:Competitors'), // Parametros de salida
$URL
);
function getCompetitors(){
global $db;
$sql = "SELECT * FROM Competitors";
$respuesta = $db->getAll($sql);
return new soapval('return', 'tns:Competitors', $respuesta );
}
$HTTP_RAW_POST_DATA = strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') == 0? (isset($GLOBALS['HTTP_RAW_POST_DATA'])? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input")) : NULL;
$server->service($HTTP_RAW_POST_DATA);