I created a web service based on PHP / MySQL. I wrote client.php as shown below:
<?php require_once("lib/nusoap.php"); $host = $_SERVER['HTTP_HOST']; $serverURL = 'http://'.$host.'/WS-Demo'; $serverScript = 'server.php'; $client = new nusoap_client("$serverURL/$serverScript?wsdl", 'wsdl'); $error = $client->getError(); if ($error) { echo '<pre style="color: red">' . $error . '</pre>'; echo '<p style="color:red;'>htmlspecialchars($cliente->getDebug(), ENT_QUOTES).'</p>'; die(); } function decryptRJ256($string_to_decrypt) { $key = 'salt_key - I'; $iv = 'salt_key - II'; $string_to_decrypt = base64_decode($string_to_decrypt); $rtn = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_decrypt, MCRYPT_MODE_CBC, $iv); $rtn = rtrim($rtn, "\4"); return($rtn); } function encryptRJ256($string_to_encrypt) { $key = 'salt_key - I'; $iv = 'salt_key - II'; $rtn = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_encrypt, MCRYPT_MODE_CBC, $iv); $rtn = base64_encode($rtn); return($rtn); } $table = array('users'); $fields = array('DisplayName','Useremail', 'UserName', 'AccountBalance'); $cnd = array('UserID', 'demo'); for($i=0;$i< count($fields); $i++) { $fields[$i] = encryptRJ256($fields[$i]); } for($i=0;$i< count($table); $i++) { $table[$i] = encryptRJ256($table[$i]); } for($i=0;$i< count($cnd); $i++) { $cnd[$i] = encryptRJ256($cnd[$i]); } $result = $client->call( "getDemoData", array('fldpara'=>$fields, 'tblpara'=>$table, 'cndpara'=>$cnd), "uri:$serverURL/$serverScript", "uri:$serverURL/$serverScript/getData" ); if ($client->fault) { echo '<b>Error: '; print_r($result); echo '</b>'; } else { $error = $client->getError(); if ($error) { echo '<b style="color: red">-Error: ' . $error . "</b><br />". mysql_error(); } else { $result = decryptRJ256($result); echo $result; } } ?>
And server.php as shown below:
<?php require_once("lib/nusoap.php"); $host = $_SERVER['HTTP_HOST']; $miURL = 'http://'.$host.'/WS-Demo'; $server = new nusoap_server(); $server->configureWSDL('My_WebService', $miURL); $server->wsdl->schemaTargetNamespace=$miURL; $server->register('getDemoData', array('fldpara' => 'xsd:Array', 'tblpara' => 'xsd:Array', 'cndpara' => 'xsd:Array'), array('return' => 'xsd:string'), $miURL); function decryptRJ256($string_to_decrypt) { $key = 'salt_key - I'; $iv = 'salt_key - II'; $string_to_decrypt = base64_decode($string_to_decrypt); $rtn = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_decrypt, MCRYPT_MODE_CBC, $iv); $rtn = rtrim($rtn, "\4"); return($rtn); } function encryptRJ256($string_to_encrypt) { $key = 'salt_key - I'; $iv = 'salt_key - II'; $rtn = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_encrypt, MCRYPT_MODE_CBC, $iv); $rtn = base64_encode($rtn); return($rtn); } function getDemoData($flds, $tbls, $cnds){ $link=mysql_connect("localhost", "root", ""); mysql_select_db("test", $link) OR DIE("Error: Database connection error"); for($i=0;$i< count($flds); $i++) { $flds[$i] = decryptRJ256($flds[$i]); } for($i=0;$i< count($tbls); $i++) { $tbls[$i] = decryptRJ256($tbls[$i]); } for($i=0;$i< count($cnds); $i++) { $cnds[$i] = decryptRJ256($cnds[$i]); } if(! empty($flds)) { $what = implode(", ", $flds); } else { $what = "*"; } if(! empty($tbls)) { $from = implode(", ", $tbls); }else { $err = 1; } if(! empty($cnds)) { $cond = " WHERE "; $cond .= $cnds[0] . " = '" . $cnds[1] . "'"; } else { $cond = ""; } $sql = "SELECT ".$what." FROM ".$from . $cond; $rsGetData = mysql_query($sql, $link); $responseData = '<?xml version="1.0" encoding="UTF-8"?> <MyDataSets>'; $responseData .= '<MyDataSet>'; $responseData .= '<SQL>'. $sql .'</SQL>'; $responseData .= '</MyDataSet>'; while($rowGetData = mysql_fetch_assoc($rsGetData)) { $responseData .= '<MyDataSet>'; foreach($rowGetData as $k => $v) { $responseData .= "<$k>$v</$k>"; } $responseData .= '</MyDataSet>'; } $responseData .= '</MyDataSets>'; $responseData = encryptRJ256($sql); $responseString = new soapval('return', 'xsd:string', $responseData ); return $responseString; } $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $server->service($HTTP_RAW_POST_DATA); ?>
From the code above, if I comment on the while loop from server.php, it gives the correct output. But if I delete comments that give me the output as "-Error: XML error parsing the SOAP payload on line 2: Invalid end of document", even if the SQL query is correct and the same works directly in phpMyAdmin.
Please help me solve debug. AS SOON AS POSSIBLE..!!! Thanks at Advance.