I'm working in a codeigniter based project with integrated SOAP webservices, and I fail to load a model function inside a registered webservice function.
I have this 2 functions in SOAP webservice: hello and addcontact.
function hello($name) {
return 'Hello, ' . $name;
}
and
function addcontact($nombre, $apellido, $ciudad) {
$resultado=$this->modelo_turismo->addcontact($nombre, $apellido, $ciudad);
if($resultado){
return "Bienvenido $nombre $apellido. Tu eres de $ciudad.";
}else{
return "No se pudo agregar contacto.";
}
}
Function hello is simple and its working fine when service is consumed by client, unlike function addcontact that is showing this message when trying to be consumed:
Response not of type text/xml: text/html
As you can see, I'm loading a function within model that inserts a contact to database, but im not even returning any database data to echo or print.
As well I've tried some other things trying to load the model, I cant get rid of that message, so I tried this (I know its weird to use a function to insert like this in CodeIgniter but im trying to learn why that message come):
function addcontact($nombre, $apellido, $ciudad) {
$conexion = new mysql ("localhost","root","","turismo");
if ($conexion->connect_errno){
return "Failed to connect to MySQL: " . $conexion->connect_error;
}
$query = "INSERT INTO contactos (nombre, apellido, ciudad) VALUES ('$nombre', '$apellido', '$ciudad')";
$resultado = $conexion->query($query);
if($resultado){
return "Bienvenido $nombre $apellido. Tu eres de $ciudad.";
}else{
return "No se pudo agregar contacto.";
}
}
with that function I get this error again:
Response not of type text/xml: text/html
But if I change the in the connection line 'mysql' to 'mysqli' like this:
$conexion = new mysqli ("localhost","root","","turismo");
I get the expected result when loading client:
Bienvenido John Travolta. Tu eres de California.
I then suspected that the error I was getting loading the model was because in my database config file I had this line:
$db['default']['dbdriver'] = 'mysql';
so I tried to change the driver to 'mysqli' and no good results. I keep getting the same error:
Response not of type text/xml: text/html
BTW, this is the way im registering 'addcontact' function:
$this->nusoap_server->register('addcontact', // method name
array('nombre' => 'xsd:string',
'apellido' => 'xsd:string',
'ciudad' => 'xsd:string'), // input parameters
array('return' => 'xsd:string'), // output parameters
'urn:Turismo_WSDL', // namespace
'urn:Turismo_WSDL#addcontact', // soapaction
'rpc', // style
'encoded', // use
'Agregar reservacion' // documentation
);
and this is the client function, that consumes the function above:
function addcontact() {
$wsdl = site_url('Webservice/wsdl');
$client = new nusoap_client($wsdl, true);
$client-> soap_defencoding='UTF-8';
$client->decode_utf8 = true;
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$result = $client->call('addcontact', array('nombre' => 'John', 'apellido'=>'Travolta', 'ciudad'=>'California'));
// Check for a fault
if ($client->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
// Check for errors
$err = $client->getError();
if ($err) {
// Display the error
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
}
So my question is, what I'm doing wrong? I can do the work with a manual connection like described above, but I want to work with the model as in CodeIgniter.