Welcome Guest, Not a member yet? Register   Sign In
CI SOAP Server Problem
#8

[eluser]JanDoToDo[/eluser]
Hey guys.

This is for everyones use and is a solution to the above.

Problem - CI doesn't seem to make SOAP integration particularly easy. In particular, the database class caused SOAP Server to fail everytime I tried to run it.

Solution - Create the functions required in the constructor of the SOAP server and call the index function from the SOAP client. Add each of the required functions in the SOAP server setup. If using the database class, replace each instance with raw PHP database functions i.e. mysql_connect, mysql_query etc. It doesn't seem to be able to load the database class and if the function is made in the constructor, it cannot reference "$this -> db" as $this is not the super object. Even if a new reference is made (which solves the reference to the db class) it causes the SOAP server to fail. My settings are as follows for when it crashed, and a sample of how i overcame it.

Settings:
Code:
$db['default']['active_r'] = TRUE;
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";


My code:

Code:
class Web_server extends Controller {

    function Web_server()
    {
        parent::__construct();
        
        function getOrders($parameters)
        {
            $username = $parameters -> username;
            $password = $parameters -> password;
            
            $user = 'xxx';
            $pass = 'xxx';
    
            $dbuser = 'xxx';
            $dbpass = 'xxx';
            $conn = mysql_connect('localhost', $dbuser, $dbpass) or die ('Error connecting to mysql');
            
            $dbname = 'delagua';
            mysql_select_db($dbname);
            
            if ($user == $username AND $pass == $password) :
                $sql = 'SELECT o.*, u.user_email FROM orders AS o LEFT JOIN users as u ON u.user_id = o.customer_id';
                if ($order_query = mysql_query($sql)) :
                    while ($order_row = mysql_fetch_array($order_query)) :
                        $order = $order_row['order_id'];
                        $cust = $order_row['user_email'];
                        $date = $order_row['order_date'];

                        $product_sql = 'SELECT od.product_id, od.product_quantity FROM orders_products AS od WHERE order_id = ' . $order;                        
                        if ($product_query = mysql_query($product_sql)) :
                            while ($product_row = mysql_fetch_array($product_query)) :
                                $data['getOrdersReturn']['remoteComment'][] = array(
                                                                                    'orderID'             => $order,
                                                                                    'customerID'         => $cust,
                                                                                    'date'                 => (string)$date,
                                                                                    'productID'         => $product_row['product_id'],
                                                                                    'productQuantity'     => $product_row['product_quantity']
                                                                                    );
                            endwhile;
                        else :
                            $data['getOrdersReturn']['remoteComment']['productID'] = 'No products found';
                        endif;
                        
                    endwhile;
                else :
                    $data['getOrdersReturn']['remoteComment'] = 'No order';
                endif;
                return $data;
            else :
                throw new SoapFault("Server", "Validation failed for username '$username'.");
            endif;
        }
        
        function getEnquiries($parameters)
        {
            $username = $parameters -> username;
            $password = $parameters -> password;
            
            $user = 'xxx';
            $pass = 'xxx';
    
            $dbuser = 'xxx';
            $dbpass = 'xxx';
            $conn = mysql_connect('localhost', $dbuser, $dbpass) or die ('Error connecting to mysql');
            
            $dbname = 'delagua';
            mysql_select_db($dbname);
            
            if ($user == $username AND $pass == $password) :                
                $data['getEnquiriesReturn']['enquiryInfo'][] = array(
                                                                    'enquiryID'         => 12,
                                                                    'customerID'         => 34,
                                                                    'date'                 => date('Y-m-d'),
                                                                    'enquiryType'         => 'From contact page',
                                                                    'enquiryComment'     => 'I thought this was a test enquiry'
                                                                    );
                return $data;
            else :
                throw new SoapFault("Server", "Validation failed for username '$username'.");
            endif;
        }
    }
    
    function index()
    {
        ini_set('soap.wsdl_cache_limit', 0);
        ini_set('soap.wsdl_cache_ttl', 0);
        $server = new SoapServer('http://www.domain.org/assets/wsdlfile.wsdl');
        $server -> addFunction('getOrders');
        $server -> addFunction('getEnquiries');
        $server -> handle();
    }
}


Messages In This Thread
CI SOAP Server Problem - by El Forum - 03-19-2010, 05:49 AM
CI SOAP Server Problem - by El Forum - 03-19-2010, 06:24 AM
CI SOAP Server Problem - by El Forum - 03-19-2010, 06:25 AM
CI SOAP Server Problem - by El Forum - 03-19-2010, 06:26 AM
CI SOAP Server Problem - by El Forum - 03-19-2010, 06:31 AM
CI SOAP Server Problem - by El Forum - 03-19-2010, 07:16 AM
CI SOAP Server Problem - by El Forum - 03-21-2010, 04:27 PM
CI SOAP Server Problem - by El Forum - 03-29-2010, 12:14 PM
CI SOAP Server Problem - by El Forum - 03-29-2010, 12:21 PM
CI SOAP Server Problem - by El Forum - 06-09-2010, 12:32 PM
CI SOAP Server Problem - by El Forum - 06-09-2010, 12:42 PM
CI SOAP Server Problem - by El Forum - 06-09-2010, 01:06 PM
CI SOAP Server Problem - by El Forum - 06-09-2010, 01:19 PM
CI SOAP Server Problem - by El Forum - 06-09-2010, 02:42 PM



Theme © iAndrew 2016 - Forum software by © MyBB