Welcome Guest, Not a member yet? Register   Sign In
Error in xml-rpc response message
#1

[eluser]kalpesh[/eluser]
Hi,
I am new in Codeigniter.
I really like this framework.
Its simple in document and use.
I am trying to create web service with xml-rpc.
In response of xml-rpc i get two errors on xmlrpc library at line 1360 and my server class at line 22 .
I dont get why this error has occured.

Code:
---DATA---
HTTP/1.1 200 OK
Date: Mon, 16 Mar 2009 14:14:14 GMT
Server: Apache/2.2.3 (Win32) PHP/5.2.0
X-Powered-By: PHP/5.2.6
Content-Length: 1545
Connection: close
Content-Type: text/xml

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined index:  0</p>
<p>Filename: controllers/mycontroller.php</p>
<p>Line Number: 22</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined index:  1</p>
<p>Filename: controllers/mycontroller.php</p>
<p>Line Number: 23</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</p>

</div>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>function</name>
<value>
<string></string>
</value>
</member>
<member>
<name>table</name>
<value>
<string></string>
</value>
</member>
<member>
<name>Pro_Id</name>
<value>
<string>242</string>
</value>
</member>
<member>
<name>Pro_Name</name>
<value>
<string>Ferrari</string>
</value>
</member>
</struct></value>
</param>
</params>
</methodResponse>
---END DATA---

The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further.

And My server class is mycontroller.php
Code:
class mycontroller extends Controller {

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

    function index()
    {
        $config['functions']['call'] = array('function' => 'mycontroller.myfunction');
        $config['functions']['call2'] = array('function' => 'mycontroller.myfunction2');
        $this->xmlrpcs->initialize($config);
        $this->xmlrpcs->serve();
    }
    function myfunction($request)
    {
    $this->load->database();
    $parameters = $request->output_parameters();
    $function = $parameters['0'];
    $table = $parameters['1'];
    if ($this->db->get('product'))
    {
        $query=$this->db->get('product');
    foreach ($query->result() as $row)
        {
          $content= $row->Pro_Id;
          $content1= $row->CarName;
        }
    }
    else
    {
    $content = 'failure';
    }
    $response = array(
    array(
    'function' => array($function, 'string'),
    'table' => array($table, 'string'),
    'Pro_Id' => array($content, 'string'),
    'CarName' => array($content1, 'string'),
    ),
    'struct');
    return $this->xmlrpc->send_response($response);
    }
}

Please help me .
Thanks in advance.
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

I'd suggest you do a var_dump on that array, as it appears to be empty.
#3

[eluser]kalpesh[/eluser]
I also var_dump on the array.
It gives me following message.

Code:
---DATA---
HTTP/1.1 200 OK
Date: Tue, 17 Mar 2009 05:23:22 GMT
Server: Apache/2.2.3 (Win32) PHP/5.2.0
X-Powered-By: PHP/5.2.6
Content-Length: 2038
Connection: close
Content-Type: text/xml

<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined index:  0</p>
<p>Filename: controllers/mycontroller.php</p>
<p>Line Number: 22</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Notice</p>
<p>Message:  Undefined index:  1</p>
<p>Filename: controllers/mycontroller.php</p>
<p>Line Number: 23</p>

</div>array(2) {
  [0]=>
  array(4) {
    ["function"]=>
    array(2) {
      [0]=>
      NULL
      [1]=>
      string(6) "string"
    }
    ["table"]=>
    array(2) {
      [0]=>
      NULL
      [1]=>
      string(6) "string"
    }
    ["Pro_Id"]=>
    array(2) {
      [0]=>
      string(3) "242"
      [1]=>
      string(6) "string"
    }
    ["Pro_Name"]=>
    array(2) {
      [0]=>
      string(11) "Monte Carlo"
      [1]=>
      string(6) "string"
    }
  }
  [1]=>
  string(6) "struct"
}
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</p>

</div><div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">

<h4>A PHP Error was encountered</h4>

<p>Severity: Warning</p>
<p>Message:  htmlspecialchars() expects parameter 1 to be string, array given</p>
<p>Filename: libraries/Xmlrpc.php</p>
<p>Line Number: 1360</p>

</div>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
<methodResponse>
<params>
<param>
<value>
<struct>
<member>
<name>function</name>
<value>
<string></string>
</value>
</member>
<member>
<name>table</name>
<value>
<string></string>
</value>
</member>
<member>
<name>Pro_Id</name>
<value>
<string>242</string>
</value>
</member>
<member>
<name>Pro_Name</name>
<value>
<string>Monte Carlo</string>
</value>
</member>
</struct></value>
</param>
</params>
</methodResponse>
---END DATA---

string(133) "The XML data receieved was either invalid or not in the correct form for XML-RPC. Turn on debugging to examine the XML data further."

This is my new mycontroller.php

Code:
class mycontroller extends Controller {

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

    function index()
    {
        $config['functions']['call'] = array('function' => 'mycontroller.myfunction');
        $config['functions']['call2'] = array('function' => 'mycontroller.myfunction2');
        $this->xmlrpcs->initialize($config);
        $this->xmlrpcs->serve();
    }
    function myfunction($request)
    {
    $this->load->database();
    $parameters = $request->output_parameters();
    $function = $parameters['0'];
    $table = $parameters['1'];
    if ($this->db->get('product'))
    {
        $query=$this->db->get('product');
    foreach ($query->result() as $row)
        {
          $content= $row->Pro_Id;
          $content1= $row->CarName;
        }
    }
    else
    {
    $content = 'failure';
    }
    $response = array(
    array(
    'function' => array($function, 'string'),
    'table' => array($table, 'string'),
    'Pro_Id' => array($content, 'string'),
    'CarName' => array($content1, 'string'),
    ),
    'struct');
     var_dump($response);
    return $this->xmlrpc->send_response($response);
    }
}

I am also giving client part.
Code:
class xmlrpc_client extends Controller {

    function xmlrpc_client()
    {
        parent::Controller();
        $this->load->library('xmlrpc');
    }
    function index()
    {
        $server_url = 'http://127.0.0.1/CodeIgniter/index.php/mycontroller';
        $this->load->library('xmlrpc');
        $this->xmlrpc->set_debug(TRUE);
        $this->xmlrpc->server($server_url, 80);
        $this->xmlrpc->method('call');
        $request = array('optimisation','product');
        if ( ! $this->xmlrpc->send_request())
            {
            var_dump($this->xmlrpc->display_error());
            }
            else
            {
            var_dump($this->xmlrpc->display_response());
            }
    }
}
#4

[eluser]TheFuzzy0ne[/eluser]
I'm sorry, I don't understand what's going wrong. I can only suggest that you keep var_dump()ing $parameters as you go, as for some reason, it's not be set the way it should be.

Also, I'd suggest changing this:
Code:
if ($this->db->get('product'))
{
    $query=$this->db->get('product');
    foreach ($query->result() as $row)
    {
        $content= $row->Pro_Id;
         $content1= $row->CarName;
    }
}

To this:

Code:
if ($query = $this->db->get('product')) # $query is set in the if statement to save running the query twice.
{
    foreach ($query->result() as $row)
    {
        $content = $row->Pro_Id;
         $content1 = $row->CarName;
    }
}




Theme © iAndrew 2016 - Forum software by © MyBB