
Nusoap + php + mysql
Publicado por esteban (1 intervención) el 03/03/2017 16:42:23
buenas mi primer post espero ser preciso en mi pregunta. tengo un webservis nusoap con una funcion que consulta una tabla de mysql y quiero hacer el cliente del wsd y no logro hacertar con los tipos de datos
y el codigo del cliente
Su ayuda seria de bendicion gracias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
require_once "lib/nusoap.php";$server = new soap_server();
//$server->configureWSDL('Servidor', 'urn:Servidor');
$ns="urn:http://localhost/ebenezer/nusoap/servicio2.php";
$server->configureWSDL('WService de ejemplo ', $ns);
$server->wsdl->schemaTargetNamespace=$ns;
$server->wsdl->addComplexType(
'Producto',
'complexType',
'struct',
'all',
'',
array('Id' => array('name' => 'Id', 'type' => 'xsd:int')
,'Codigo' => array('name' => 'Codigo', 'type' => 'xsd:string')
,'Nombre' => array('name' => 'Nombre', 'type' => 'xsd:string')
,'Descripcion' => array('name' => 'Descripcion', 'type' => 'xsd:string')
,'Imagen' => array('name' => 'Imagen', 'type' => 'xsd:string')
,'Precio' => array('name' => 'Precio', 'type' => 'xsd:double')
,'Existencia' => array('name' => 'Existencia', 'type' => 'xsd:int')
,'ExistenciaMin' => array('name' => 'ExistenciaMin', 'type' => 'xsd:int')
));$server->wsdl->addComplexType(
'Productos',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Producto[]')),
'tns:Producto');$server->wsdl->addComplexType(
'Respuesta',
'complexType',
'struct',
'all',
'', array(
'Ok' => array('name' => 'Ok', 'type' => 'xsd:boolean')
,'Mensaje' => array('name' => 'Mensaje', 'type' => 'xsd:string')
));
$server->register(
'ObtenerItem',array('id' => 'xsd:int')
,array('return' => 'tns:Producto')
,$ns,$ns . '#ObtenerItem'
,'rpc'
,'encoded'
,'Obtiene un Item en la base de Datos.'
);$server->register(
'ObtenerItems',array()
,array('return' => 'tns:Productos')
,$ns,$ns . '#ObtenerItems'
,'rpc'
,'encoded'
,'Obtiene una Lista Items en la base de Datos.'
);function ObtenerItem($id) {
$conexion = new PDO("mysql:host=localhost;dbname=v0030857_ebenezer","v0030857_root" ,"ESTEban36");
$query = "SELECT Id,Codigo,Nombre,Descripcion,Imagen,Precio,Existencia,ExistenciaMin FROM producto WHERE Id=".$id;
$pdolink = $conexion->prepare($query);
$pdolink->execute();
$producto = $pdolink->fetch(PDO::FETCH_ASSOC);
$persona = array('Id'=>'1', 'Codigo'=>'Codigo',
'Nombre'=>'Nombre' ,
'Descripcion'=>'Descripcion' ,
'Imagen'=>'Imagen' ,
'Precio'=>'2.2' ,
'Existencia'=>'1',
'ExistenciaMin'=>'45',
);return new soapval('return', 'tns:Producto', $persona);
}function ObtenerItems() {
$conexion = new PDO("mysql:host=localhost;dbname=v0030857_ebenezer","v0030857_root" ,"ESTEban36");
$query = "SELECT Id,Codigo,Nombre,Descripcion,Imagen,Precio,Existencia,ExistenciaMin FROM producto ";
$pdolink = $conexion->prepare($query);
$pdolink->execute();
$producto = $pdolink->fetchAll(PDO::FETCH_ASSOC);
return new soapval('return', 'tns:Productos', $productos);
}$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
y el codigo del cliente
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
require_once "nusoap/lib/nusoap.php";$response= $client->call('ObtenerItem','98775');
var_dump($response);
//Codigo para debugear y ver la respuesta y posibles errores, comentar cuando se comprueba que está correcto el servicio y la llamada
$err = $client->getError();
if ($err) {
echo '<p><b>Constructor error: ' . $err . '</b></p>';
}echo '<h2>Request</h2>';echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
echo htmlspecialchars($client->response, ENT_QUOTES) . '</b></p>';
echo '<p><b>Debug: <br>';echo htmlspecialchars($client->debug_str, ENT_QUOTES) .'</b></p>';
//Comentar hasta aquí
if($client->fault)
{echo "FAULT: <p>Code: (".$client->faultcode.")</p>";
echo "String: ".$client->faultstring;
}else
{ //var_dump ($response);
echo "Codigo: ".$response['Codigo'];
}Su ayuda seria de bendicion gracias
Valora esta pregunta


0