NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Problem adding complex type array


Joined: 24 Jan 2008
Posts: 1
Location: BE
Reply with quote
Hello everyone,

I made a "small" server and client script to transfer a complete table from mysql to the client. I think i did everything by the book but i can't seem to get it working.
The array is populated when sending the request to the client. (I tested this true email), but the client doesn't seem to understand the array ?

Please help me out guys, Tnx
Ilias

Output Client => http://myserver/soap_client.php#

Client code =>
<?php
//WORKS WITH PHP4 PHP5, WINDOWS, UNIX

//CONFIGURATION
$soap_server = 'https://myserver/soap_server.php?wsdl';

$email = "admin@craftedbyinfinity.com"; //YOUR EMAIL ADRESS
$password = "xxxxxxxxxx"; //YOUR PASSWORD

$use_proxy = false; //SET TO "true" IF YOU WANT TO USE PROXY
$proxyhost = ""; //USE IN CASE OF PROXY
$proxyport = ""; //USE IN CASE OF PROXY
$proxyusername = ""; //USE IN CASE OF PROXY
$proxypassword = ""; //USE IN CASE OF PROXY

$debug = true; //SET TO TRUE IF SCIPTS GOES PUBLIC
$encoding = "UTF-8"; //ENCODING SETTINGS, USE CAPITALS


//////////////////////////////////////////////////////////////////////////////////////////////
//LOAD THE NUSOAP CLASS
require_once('functions/soap/nusoap.php');

//LOAD UP AN INSTANCE
if ($use_proxy) {
//CHECK IF PROXY IS USED
if (empty($proxyhost) || empty($proxyport) || empty($proxyusername) || empty($proxypassword)) {
die("Check your proxy configuration.");
}else{
$client = new nusoap_client($soap_server, 'wsdl',$proxyhost, $proxyport, $proxyusername, $proxypassword);
}
} else {
$client = new nusoap_client($soap_server, 'wsdl');
}

//CHANGE DEFAULT ENCODING TO ...
if ($encoding == "UTF-8") {
$client->soap_defencoding = $encoding; //ENCODING SETTINGS
$client->decode_utf8 = false;
}


//ENABLE OR DISABLE DEBUGGING
$client->debug_flag = $debug;

//ERRORS ?
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}

//SEND USERNAME AND PASSWORD
if (empty($email) || !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email) || empty($password)) {
die("Check your email and password settings.");
}else{
$client->setCredentials($email, $password, 'basic');
}

//MAKE THE CALL
$result .= "<br/>RESULT getStones:".$client->call('getStones');

//ERRORS ?
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>';
}
}

//DISLPAY ALL TRANSFER DATA
if ($debug) {
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
// Display the debug messages
echo '<h2>Debug</h2>';
echo '<pre>' . htmlspecialchars($client->debug_str, ENT_QUOTES) . '</pre>';
}

//DESTROY $client
unset($client);
?>


Server Code =>
<?php
//LOAD SETTINGS
require_once("settings.php");

//INCLUDE DATABASE ABSTRACTION FILES AND CONFIGURE CONNECTION TYPE
require_once("functions/adodb5/adodb.inc.php");
require_once("functions/adodb5/adodb-exceptions.inc.php");

//START SESSION
if (session_id() == "") {
session_start();
}

//CHECK CACHING DIR EN SETUP ADODB CACHE DIR
clearstatcache();
if (is_writable($protected_directory)) {
$ADODB_CACHE_DIR = $protected_directory.'/cache/';
} else {
echo ("Protected directory is not writable");
exit();
}

//START DATABASE CONNECTION
$dsn = $db_type."://".$db_username.":".$db_password."@".$db_host."/".$db_name."?persist";
$_SESSION["database"] = NewADOConnection($dsn);
$_SESSION["database"]->cacheSecs = $db_cache_time;
if (!$_SESSION["database"])die ("Check your configuration file. Unable to connect to the database.");
//SAY YOU WANT NAMES RETURNED INSTEAD OF REGULAR NUMBERS
$_SESSION["database"]->SetFetchMode(ADODB_FETCH_ASSOC);
$db = $_SESSION["database"];

//LOAD NUSOAP
require_once('functions/soap/nusoap.php');

$realm = 'Soap Server - Restricted Access';

if (!isset($_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="'.$realm.'"');
header('HTTP/1.0 401 Unauthorized');
die ('Authorization Required');
}elseif(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_SERVER['PHP_AUTH_USER'])) {
header('WWW-Authenticate: Basic realm="'.$realm.'"');
header('HTTP/1.0 401 Unauthorized');
die ('Incorrect email format.');
}else{
//QUERY DOEN
$recordSet = $db->Execute(" SELECT
id,
email,
status
FROM users
WHERE email ='" . $_SERVER['PHP_AUTH_USER'] ."'
AND password ='" . bin2hex(mhash(MHASH_SHA256,$_SERVER['PHP_AUTH_PW'],$secret_key)) ."'");


if (!$recordSet) {
echo $db->ErrorMsg();
$recordSet->Close();
$db->Close();
die ('Probem with server.');
} elseif(count($recordSet->fields) < 2) {
header('WWW-Authenticate: Basic realm="'.$realm.'"');
header('HTTP/1.0 401 Unauthorized');
die ('Incorrect email or password.');
} elseif($recordSet->fields["status"] == 0) {
//ACCOUNT DEACTIVATED
header('WWW-Authenticate: Basic realm="'.$realm.'"');
header('HTTP/1.0 401 Unauthorized');
die("This account has been deactivated by the site administrator.");
}else{
//REGISTER THE USER_ID
$_SESSION["user_id"] = $recordSet->fields["id"];

//START SERVER INSTANCE
$server = new soap_server();

$server->soap_defencoding = 'UTF-8';
$server->decode_utf8 = true;

//Initialize WSDL support
$namespace = "https://myserver/soap_server.php?wsdl";
$server->configureWSDL('Infinity', $namespace);
$server->wsdl->schemaTargetNamespace = $namespace;

//ADD COMPLEX DATA TYPE
$server->wsdl->addComplexType(
'Walk',
'complexType',
'struct',
'all',
'',
array( 'id' => array('name'=>'id','type'=>'xsd:int'),
'reference_id' => array('name'=>'reference_id','type'=>'xsd:string'),
'price_basic' => array('name'=>'price_basic','type'=>'xsd:string'),
'price_basic_pro' => array('name'=>'price_basic_pro','type'=>'xsd:string'),
'price_retailer_pro'=> array('name'=>'price_retailer_pro','type'=>'xsd:string'),
'grading_report' => array('name'=>'grading_report','type'=>'xsd:string'),
'grading_nr' => array('name'=>'grading_nr','type'=>'xsd:string'),
'shape_id' => array('name'=>'shape_id','type'=>'xsd:int'),
'cut_grade' => array('name'=>'cut_grade','type'=>'xsd:int'),
'color_grade' => array('name'=>'color_grade','type'=>'xsd:int'),
'clarity_grade' => array('name'=>'clarity_grade','type'=>'xsd:int'),
'weight' => array('name'=>'weight','type'=>'xsd:string'),
'fluorescence' => array('name'=>'fluorescence','type'=>'xsd:string'),
'measurements' => array('name'=>'measurements','type'=>'xsd:string'),
'brightness' => array('name'=>'brightness','type'=>'xsd:string'),
'girdle' => array('name'=>'girdle','type'=>'xsd:string'),
'contrast' => array('name'=>'contrast','type'=>'xsd:string'),
'culet' => array('name'=>'culet','type'=>'xsd:string'),
'dispersion' => array('name'=>'dispersion','type'=>'xsd:string'),
'polish' => array('name'=>'polish','type'=>'xsd:string'),
'leakage' => array('name'=>'leakage','type'=>'xsd:string'),
'symmetry' => array('name'=>'symmetry','type'=>'xsd:string'),
'weight_ratio' => array('name'=>'weight_ratio','type'=>'xsd:string'),
'tilt' => array('name'=>'tilt','type'=>'xsd:string'),
'durability' => array('name'=>'durability','type'=>'xsd:string'),
'table_size' => array('name'=>'table_size','type'=>'xsd:string'),
'total_depth' => array('name'=>'total_depth','type'=>'xsd:string'),
'pav_angle' => array('name'=>'pav_angle','type'=>'xsd:string'),
'crown_angle' => array('name'=>'crown_angle','type'=>'xsd:string'),
'pic_grading' => array('name'=>'pic_grading','type'=>'xsd:string'),
'pic_loupe' => array('name'=>'pic_loupe','type'=>'xsd:string'),
'pic_hearts' => array('name'=>'pic_hearts','type'=>'xsd:string'),
'pic_arrows' => array('name'=>'pic_arrows','type'=>'xsd:string'),
'pic_idealscope' => array('name'=>'pic_idealscope','type'=>'xsd:string'),
'pic_asetscope' => array('name'=>'pic_asetscope','type'=>'xsd:string'),
'pic_engraving' => array('name'=>'pic_engraving','type'=>'xsd:string'),
'pic_extra1' => array('name'=>'pic_extra1','type'=>'xsd:string'),
'pic_extra2' => array('name'=>'pic_extra2','type'=>'xsd:string'),
'pic_extra3' => array('name'=>'pic_extra3','type'=>'xsd:string'),
'pic_extra4' => array('name'=>'pic_extra4','type'=>'xsd:string'),
'sarin' => array('name'=>'sarin','type'=>'xsd:string'),
'gemadvisor' => array('name'=>'gemadvisor','type'=>'xsd:string'),
'helium1' => array('name'=>'helium1','type'=>'xsd:string'),
'helium2' => array('name'=>'helium2','type'=>'xsd:string'),
'status' => array('name'=>'status','type'=>'xsd:int'),
'comments' => array('name'=>'comments','type'=>'xsd:string'),
'comments2' => array('name'=>'comments2','type'=>'xsd:string'),
'datetime_create' => array('name'=>'datetime_create','type'=>'xsd:string'),
'datetime_change' => array('name'=>'datetime_change','type'=>'xsd:string')
)
);


//ADD ANOTHER COMPLEX DATA TYPE
$server->wsdl->addComplexType(
'Walks',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:Walk[]')
),
'tns:Walk'
);


//REGISTER THE FUNCTION
$server->register( 'getStones', // method name
array(), // input parameters
array('return' => 'tns:walk'), // output parameters
$namespace, // namespace
$namespace.'#getStones', // soapaction
'rpc', // style
'encoded', // use
'Get all the stones in your database' // documentation
);


//FUNCTIONS
function getStones() {
$recordSet = $_SESSION["database"]->Execute("SELECT
id,
reference_id,
price_basic,
price_basic_pro,
price_retailer_pro,
grading_report,
grading_nr,
shape_id,
cut_grade,
color_grade,
clarity_grade,
weight,
fluorescence,
measurements,
brightness,
girdle,
contrast,
culet,
dispersion,
polish,
leakage,
symmetry,
weight_ratio,
tilt,
durability,
table_size,
total_depth,
pav_angle,
crown_angle,
pic_grading,
pic_loupe,
pic_hearts,
pic_arrows,
pic_idealscope,
pic_asetscope,
pic_engraving,
pic_extra1,
pic_extra2,
pic_extra3,
pic_extra4,
sarin,
gemadvisor,
helium1,
helium2,
status,
comments,
comments2,
datetime_create,
datetime_change
FROM stones
WHERE owner_id = '".$_SESSION["user_id"]."'");

$counter = 0;
$main_array = array();
while (!$recordSet->EOF) {
$main_array[] = $recordSet->fields;
$recordSet->MoveNext();
++ $counter;
}
if ($counter == 0) {
return new soap_fault("Client","","No such stones have been found.");
}
$recordSet->Close();

return $main_array;
}

// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
}
}
?>
View user's profileFind all posts by dbassSend private message
Problem adding complex type array
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic