Welcome Guest, Not a member yet? Register   Sign In
[help] Xml-rpc always the same error
#1

[eluser]Unknown[/eluser]
Good Morning to all,

I need help with a connection between a client and a server using xmlrpc library of codeigniter.

I'm doing a web-service here and now need a successfully response of web-service to my application, but always presents the same error.

I have a web system built with ExtJs + PHP and I need that whenever there a register of somebody in the system, it needs to be saved in the web service. The response of web-service will be the ID registered in the database.

controller:
Quote:public function webServInsertPeople() {
$this->load->library("people/People");

$data = array();
$data["id"] = $this->input->post("cad_id");
$data["name"] = $this->input->post("cad_nome");
$data["email"] = '';
$data["residential_phone"] = $this->input->post("cad_telefone");
$data["cell_phone"] = '';
$data["commercial_phone"] = '';
$data["cpf_cnpj"] = $this->input->post("cad_cpf_cnpj");
$data["address"] = $this->input->post("cad_endereco");
$data["delivery_address"] = $this->input->post("cad_endereco_entrega");
$data["billing_address"] = $this->input->post("cad_endereco_cobranca");
$data["website"] = $this->input->post("cad_website");
$data["description"] = $this->input->post("cad_descricao");
$data["branch"] = $this->input->post("cad_ramo");
$data["social_networks"] = $this->input->post("cad_redes_sociais");

echo $this->people->insertPeople($data);

}

library:

Quote:class People {

public function __construct() {

$this->CI =& get_instance();

}

public function index(){

}

public function insertPeople($data){
//Carrega a library do xmlrpc
$this->CI->load->library('xmlrpc')

//cofig that contains the url of the web-service.
$this->CI->config->load('chefao',TRUE,TRUE);
$server_url = $this->CI->config->item("server_url","chefao");

//Recebe a variavel com a url do web service e a porta do mesmo
$this->CI->xmlrpc->server($server_url, "80");
//nome do metodo para fazer referencia la no web services
$this->CI->xmlrpc->method('people.insert');
//linha para debug
$this->CI->xmlrpc->set_debug(true);

$request = array(
array(
array(
'id' => $data['id'],
'name' => $data['name'],
'email' => $data['email'],
'residential_phone' => $data['residential_phone'],
'cell_phone' => $data['cell_phone'],
'commercial_phone' => $data['commercial_phone'],
'cpf_cnpj' => $data['cpf_cnpj'],
'address' => $data['address'],
'delivery_address' => $data['delivery_address'],
'billing_address' => $data['billing_address'],
'website' => $data['website'],
'description' => $data['description'],
'branch' => $data['branch'],
'social_networks' => $data['social_networks']
), "struct"
)
);

$this->CI->xmlrpc->request($request);

if (!$this->CI->xmlrpc->send_request()) {
return returnSuccess(false, $this->CI->xmlrpc->display_error());
} else {
return returnSuccess(true, $this->CI->xmlrpc->display_response());
}
}

.
.
.

api of web-service:
Quote:class Api extends CI_Controller {

public function __construct() {
parent::__construct();
$this->load->library('xmlrpc');
$this->load->library('xmlrpcs');
}

public function index() {

$this->load->library('people/People');

$config['functions']['people.insert'] = array('function' => 'people.save');


$config['object'] = $this;

$this->xmlrpcs->initialize($config);
$this->xmlrpcs->serve();
}

}

Continue...
#2

[eluser]Unknown[/eluser]
library of web-service:
Quote:class People {

protected $CI;
protected $xmlrpc;
/*-------------------------------------------------------------------------
* Retornan constants that the error
* message if a field is not filled
*/
const ERROR_NAME = "ERRO: Informe o name para cadastro";
const ERROR_PHO_COMMERCIAL = "ERRO: Informe o commercial_phone para cadastro";
const ERROR_ATUALIZAR_DADOS = "ERRO: Falha na atualização dos dados";
const ERROR_DELETE = "ERRO: Informe o id para excluir o registro";


public function __construct() {
$this->CI =& get_instance();

$this->CI->load->library('xmlrpc');
$this->CI->load->model("people_model", 'people');
$this->CI->people = new People_Model();

$this->xmlrpc =& $this->CI->xmlrpc;

}

public function save(XML_RPC_Message $request)
{
$parameters = $request->output_parameters(true);
if (count($parameters) == 0)
return $this->CI->xmlrpc->send_error_message("404", "Data not found");
$parameter = $parameters[0];
$data = $parameter;
if (isset($data['id']) && !empty($data['id']) ) {
return self::update($data);
} else {
return self::insert($data);
}
}

public function insert($data){

$CI =& get_instance();
$CI->load->model("people_model", 'people');
$CI->people = new People_Model();
$CI->load->library('xmlrpc');

$name = (isset ($data['name'])) ? $data['name'] : "";
if(empty ($name)){
return People::ERROR_NAME;
}

$email = (isset ($data['email'])) ? $data['email'] : "";

$cellPhone = (isset ($data['cell_phone'])) ? $data['cell_phone'] : "";

$commercialPhone = (isset ($data['commercial_phone'])) ? $data['commercial_phone'] : "";

$residencialPhone = (isset ($data['residential_phone'])) ? $data['residential_phone'] : "";
$cpfCnpj = (isset ($data['cpf_cnpj'])) ? $data['cpf_cnpj'] : "";
$address = (isset ($data['address'])) ? $data['address'] : "";
$deliveryAddress = (isset ($data['delivery_address'])) ? $data['delivery_address'] : "";
$billingAddress = (isset ($data['billing_address'])) ? $data['billing_address'] : "";
$description = (isset ($data['description'])) ? $data['description'] : "";
$website = (isset ($data['website'])) ? $data['website'] : "";
$branch = (isset ($data['branch'])) ? $data['branch'] : "";
$socialNetworks = (isset ($data['social_networks'])) ? $data['social_networks'] : "";

$data = array(
'nome' => $name,
'email' => $email,
'tel_celular' => $cellPhone,
'tel_comercial' => $commercialPhone,
'tel_residencial' => $residencialPhone,
'cpf_cnpj' => $cpfCnpj,
'endereco' => $address,
'endereco_entrega' => $deliveryAddress,
'endereco_cobranca' => $billingAddress,
'descricao' => $description,
'website' => $website,
'ramo' => $branch,
'redes_sociais' => $socialNetworks,
);

try {
$id = $CI->people->add($data);

} catch (Exception $exc) {
return $CI->xmlrpc->send_error_message("500", People::ERROR_SAVE);
}

$returnMessage = "Salvo com sucesso!";

$response = array(
array(
'id' => $id,
'message' => $returnMessage
),
'struct'
);

return $CI->xmlrpc->send_response($response);
}

The data is being saved in the web service database, but does not return the response to my web system.

Presents this error:
Quote:Content-Type: text/xml
Connection: close
Content-Length: 39

<?xml version="1.0" encoding="UTF-8"?>

---END DATA---

</pre>{"success":false,"msg":"The XML data received was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further."}

Please somebody help me...




Theme © iAndrew 2016 - Forum software by © MyBB