Servicio SOAP PHP

Tanto para el servidor como para el cliente se utiliza la libreria nusoap.

El php servidor seria asi:


require_once("lib/nusoap.php");

function getMetodo1($parametro1,$parametro2){

$res = array(array('id' => '1', 'nombre' => 'nombre1'),
array('id' => '2', 'nombre' => 'nombre2'));

return $res;

}


$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server = new soap_server;
$server->configureWSDL('items', 'urn:'.$_SERVER['SCRIPT_URI']);
$server->wsdl->addComplexType(
'Item',
'complexType',
'struct',
'all',
'',
array(
'id' => array('name' => 'id', 'type' => 'xsd:string'),
'nombre' => array('name' => 'nombre', 'type' => 'xsd:string'),
)
);

$server->wsdl->addComplexType(
'ItemArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Item[]')
),
'tns:Item'
);

$server->register('getMetodo1',
array('parametro1' => 'xsd:string', 'parametro2' => 'xsd:string'), // input parameters
array('return' => 'tns:ItemArray'),
'urn:'.$_SERVER['SCRIPT_URI'], // namespace
'urn:'.$_SERVER['SCRIPT_URI']."#getMetodo1", // soapaction
'rpc', // style
'encoded', // use
'Documentacion sobre el servicio'); // documentation

#$server->wsdl->schemaTargetNamespace = $_SERVER['SCRIPT_URI'];
$server->service($HTTP_RAW_POST_DATA);
exit();


El php cliente:

require_once('lib/nusoap.php');
$soapclient = new nusoap_client('http://84.124.186.232/Biblioteca/ServiciosWeb/1server1.php');
$result = $soapclient->call( 'getMetodo1' , array('parametro1' => 'valorParametro1','parametro2' => 'valorParametro2'));
print_r($result);
//echo($soapclient->request);
echo($soapclient->response);
//echo($soapclient->debug_str);