I'm new on Soap\NuSoap
I can connect to server site but from server send data back to client i can not get data in array to show client site. I have to test to get data and send data back to other database. I have to get in array.
it's show error
XML error parsing SOAP payload on line 2: Invalid document end
I can't fix it by myself. please help.
This is my client.php
include("lib/nusoap.php");
$client = new nusoap_client("http://192.168.20.3/soap_server/webservice.php?wsdl");
$client->soap_defencoding = 'utf-8';
$client->encode_utf8 = false;
$client->decode_utf8 = false;
$params = array(
'strName' => $_POST["strName"],
);
$result = $client->call("resultCustomer",$params);
$err = $client->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
exit();
}
print_r($result);
And this is server.php
require_once("lib/nusoap.php");
//Define our namespace
$namespace = "http://localhost/soap_server/webservice.php";
//Create a new soap server
$server = new soap_server();
//Configure our WSDL
$server->configureWSDL("getCustomer");
$server->wsdl->schemaTargetNamespace = $namespace;
$server->soap_defencoding = 'utf-8';
$server->encode_utf8 = false;
$server->decode_utf8 = false;
//Register our method and argument parameters
$varname = array(
'strName' => "xsd:string"
);
//Add ComplexType
$server->wsdl->addComplexType(
'ArrayOfString',
'complexType',
'array',
'',
'',
array(
'id_user' => array('name' => 'id_user', 'type' => 'xsd:string'),
'firstname' => array('name' => 'firstname', 'type' => 'xsd:string'),
'username' => array('name' => 'username', 'type' => 'xsd:string'),
'lastname' => array('name' => 'lastname', 'type' => 'xsd:string')
)
);
//Add ComplexType
$server->wsdl->addComplexType(
'ArrayOfString',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:DataList[]')
),
'tns:DataList'
);
// Register service and method
$server->register('resultCustomer',$varname, array('return' => 'tns:ArrayOfString'));
function resultCustomer($strName)
{
$objConnect = mysql_connect("localhost","root","") or die(mysql_error());
$objDB = mysql_select_db("qpt-test");
$strSQL = "SELECT * FROM qpt_user where firstname like '%".$strName."%'";
$objQuery = mysql_query($strSQL) or die (mysql_error());
$intNumField = mysql_num_fields($objQuery);
$resultArray = array();
while($obResult = mysql_fetch_array($objQuery))
{
$arrCol = array();
for($i=0;$i<$intNumField;$i++)
{
$arrCol[mysql_field_name($objQuery,$i)] = $obResult[$i];
}
array_push($resultArray,$arrCol);
}
return $resultArray;
}
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
// pass our posted data (or nothing) to the soap service
$server->service($POST_DATA);
exit();
Related
I'm trying to get a complex type from a php server with an operation to get an array of animals (complex type defined in the wsdl), this array is defined as ConjuntAnimals as an array of Animal objects.
But when I do the $result = $client->call('consulta_gossos', $params); I get returned a bool (false). I've been debugging and logging for a long time, and I've seen that inside the soap operation, just before returning, its value is an array of animals (what it should return), but in the client I don't get this returned.
After realizing it, I guess maybe it is the complexType definitions which I have wrong, but I've compared with a lot of examples and shouldn't be this...
Also, (maybe it helps) I get this error logged:
[10-Dec-2016 12:59:11 America/New_York] PHP Catchable fatal error: Object of class stdClass could not be converted to string in /home/cabox/workspace/lib/nusoap.php
on line 6132
[10-Dec-2016 12:59:11 America/New_York] Response not of type text/xml: text/html
I understand it expects an xml response, so I've tried to return json_encode($gossos) instead of just $gossos, but then it logs this:
[10-Dec-2016 13:11:34 America/New_York] XML error parsing SOAP payload on line 2: Invalid document end
Here I add both client and server code:
client:
<?php
require_once('./lib/nusoap.php');
$wsdl='http://php-ad-msk1416368101.codeanyapp.com/soapserver.php?wsdl';
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
$client = new nusoap_client($wsdl,'wsdl');
$client->encode_utf8 = false;
$client->decode_utf8 = false;
$client->soap_defencoding = 'utf-8';
$err = $client->getError();
if ($err) {
echo "Constructor error" . $err;
exit();
}
$edat = $_GET['edat'];
$raca = $_GET['raca'];
$vacunat = $_GET['vacunes'];
echo '<pre>' . htmlspecialchars($client->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($client->response, ENT_QUOTES) . '</pre>';
$result = $client->call('consulta_gossos', array('edat' => $edat, 'raca' => $raca, 'vacunat' => $vacunat));
$err = $client->getError();
error_log($err);
error_log(json_encode($result));
echo 'Type: '.gettype($result).', size: '.sizeOf($result);
?>
`
<?php
require_once('./lib/nusoap.php');
ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
error_log( "Hello, errors!" );
$server = new nusoap_server;
$server->soap_defencoding = 'utf-8';
$server->encode_utf8 = false;
$server->decode_utf8 = false;
$server->configureWSDL('server','urn:server');
$server->wsdl->schemaTargetNamespace = 'urn:server';
$server->wsdl->addComplexType('Animal',
'complexType',
'struct',
'all',
'',
array(
'xip' => array('name' => 'xip', 'type' => 'xsd:int'),
'nom' => array('name' => 'nom', 'type' => 'xsd:string'),
'edat' => array('name' => 'edat', 'type' => 'xsd:int'),
'vacunat' => array('name' => 'vacunat', 'type' => 'xsd:string'),
'menjar' => array('name' => 'menjar', 'type' => 'xsd:string'),
'data_entrada' => array('name' => 'data_entrada', 'type' => 'xsd:string'),
)
);
$server->wsdl->addComplexType('ConjuntAnimals',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(
array('ref'=>'SOAP-ENC:arrayType',
'wsdl:arrayType'=>'tns:Animal[]')
),
'tns:Animal'
);
$server->register('consulta_gossos',
array('edat' => 'xsd:string',
'raca' => 'xsd:string',
'vacunat' => 'xsd:string'),
array('return' => 'tns:ConjuntAnimals'), //output
'urn:server', //namespace
'urn:server#consulta_gossos', //SOAP action
'rpc',
'encoded',
'Consultar els gossos que compleixen el filtre');//description
function consulta_gossos($edat, $raca, $vacunat) {
$servername = 'localhost';
$username = 'root';
$password = 'root';
$dbname = 'bd_refugi';
$vacunes = ($vacunat =='si') ? 1 : 0;
$sql_edat = ($edat == 'gran') ? ' edat > 5 ' : ' edat <= 5 ';
$connection = new mysqli($servername, $username, $password, $dbname);
$sql = 'select * from gossos where '.$sql_edat.' and raca="'.$raca.'" and vacunat='.$vacunes;
$res = $connection->query($sql);
$gossos = array();
while ($row=$res->fetch_assoc()) {
$gos->xip=$row['xip'];
$gos->nom=$row['nom'];
$gos->edat=$row['edat'];
$gos->vacunat=$row['vacunat'];
$gos->menjar=$row['menjar'];
$gos->data_entrada=$row['data_entrada'];
array_push($gossos,$gos);
}
error_log(json_encode($gossos));
error_log('-----------------------------------------');
return json_encode($gossos);
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
`
Sorry for the indenting, my eyes are bleeding too after copy-pasting the code here.
Edit: leaving aside the errors shown above, the question intends to focus more on why returning a "correct" array, in the client I get an empty array once I've get rid off all these errors.
After several hours of debugging and testing each type individually, I've finally managed to solve this.
I was returning an array composed by what I would call structs (sorry I'm new to PHP, still don't know the slang) build from what I was getting from the mysql query. The thing is that they should have been arrays, so I add the code I've changed:
Before (not working):
$res = $connection->query($sql);
$gossos = array();
while ($row=$res->fetch_assoc()) {
$gos->xip=$row['xip'];
$gos->nom=$row['nom'];
$gos->edat=$row['edat'];
$gos->vacunat=$row['vacunat'];
$gos->menjar=$row['menjar'];
$gos->data_entrada=$row['data_entrada'];
array_push($gossos,$gos);
}
return json_encode($gossos);
After (working):
$res = $connection->query($sql);
$gossos = array();
while ($row=$res->fetch_assoc()) {
$gos = array('xip' => intval($row['xip']),
'nom' => $row['nom'],
'edat' => intval($row['edat']),
'vacunat' => $row['vacunat'],
'menjar' => $row['menjar'],
'data_entrada' => $row['data_entrada'],
'sexe' => $row['sexe'],
'raca' => $row['raca']
);
array_push($gossos,$row);
}
return $gossos;
I also was returning the json encoding (I really don't know why, I guess for trying things...), now I can return the array without getting those errors I had.
Edit: Oh! And commented line 6132 in nusoap.php, without doing it, would still get errors!
I'm trying to connect to Royal Mail shipping API, but I'm receiving the famous Could not connect to host.
$api_password = "****";
$api_username = "****";
$api_application_id = "****";
$api_service_type = "D";
$api_service_code = "SD1";
$api_service_format = "";
$api_certificate_passphrase = "****";
$time = gmdate('Y-m-d\TH:i:s');
$created = gmdate('Y-m-d\TH:i:s\Z');
$nonce = mt_rand();
$nonce_date_pwd = xyz(copy from sample);
$passwordDigest = zyz(copy from sample);
$ENCODEDNONCE = zyz(copy from sample);
$soapclient_options = array();
$soapclient_options['cache_wsdl'] = 'WSDL_CACHE_NONE';
$soapclient_options['local_cert'] = "CA2+Splash+Felipe+RM10001654+usr.p12";
$soapclient_options['passphrase'] = $api_certificate_passphrase;
$soapclient_options['trace'] = true;
$soapclient_options['ssl_method'] = 'SOAP_SSL_METHOD_SSLv3';
$soapclient_options['location'] = '****';
//launch soap client
$client = new SoapClient("SAPI/ShippingAPI_V2_0_8.wsdl", $soapclient_options);
$client->__setLocation($soapclient_options['location']);
(setting header)
$HeaderObject = new SoapVar( $HeaderObjectXML, XSD_ANYXML );
//push soap header
$header = new SoapHeader( 'oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Security', $HeaderObject );
$client->__setSoapHeaders($header);
(setting request part)
if($api_service_enhancements != "") {
$request['requestedShipment']['serviceEnhancements'] = array('enhancementType' => array('serviceEnhancementCode' => array('code' => $api_service_enhancements)));
}
//try make the call
try {
$response = $client->__soapCall('createShipment', array($request), array('soapaction' => '***api-link***') );
} catch (Exception $e) {
//catch the error message and echo the last request for debug
echo $e->getMessage();
echo "REQUEST:\n" . $client->__getLastRequest() . "\n";
die;
}
Is it correct the way I'm setting the connection and the local cert?
Is any information I'm missing?
Thanks & Regards
Follow my final code :) this one works for sure. Even have the retry in case the server is buzy, enjoy.
<?php
//ini_set('soap.wsdl_cache_enabled', '1');
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
class royalmaillabelRequest
{
private $apiapplicationid = "insert urs";
private $api_password = "insert urs";
private $api_username = "insert urs"; //"rxxxxxAPI"
private $api_certificate_passphrase = "insert urs";
private $locationforrequest = 'https://api.royalmail.com/shipping/onboarding'; //live 'https://api.royalmail.com/shipping' onbording 'https://api.royalmail.com/shipping/onboarding'
private $api_service_enhancements = "";
private function preparerequest(){
//PASSWORD DIGEST
$time = gmdate('Y-m-d\TH:i:s');
$created = gmdate('Y-m-d\TH:i:s\Z');
$nonce = mt_rand();
$nonce_date_pwd = xyz(copy from sample);
$passwordDigest = nyz(copy from sample);
$ENCODEDNONCE = (copy from sample);
//SET CONNECTION DETAILS
$soapclient_options = array();
$soapclient_options['cache_wsdl'] = 'WSDL_CACHE_NONE';
$soapclient_options['stream_context'] = stream_context_create(
array('http'=>
array(
'protocol_version'=>'1.0'
, 'header' => 'Connection: Close'
)
)
);
$soapclient_options['local_cert'] = dirname(__FILE__) . "/certificate.pem";
$soapclient_options['passphrase'] = $this->api_certificate_passphrase;
$soapclient_options['trace'] = true;
$soapclient_options['ssl_method'] = 'SOAP_SSL_METHOD_SSLv3';
$soapclient_options['location'] = $this->locationforrequest;
$soapclient_options['soap_version'] = 'SOAP_1_1';
//launch soap client
$client = new SoapClient(dirname(__FILE__) . "/SAPI/ShippingAPI_V2_0_8.wsdl", $soapclient_options);
$client->__setLocation($soapclient_options['location']);
//headers needed for royal mail//D8D094Fd2716E3Es142588808s317
$HeaderObjectXML = '<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-D8D094FC22716E3EDE14258880881317">
<wsse:Username>'.$this->api_username.'</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">'.$passwordDigest.'</wsse:Password>
<wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">'.$ENCODEDNONCE.'</wsse:Nonce>
<wsu:Created>'.$created.'</wsu:Created>
</wsse:UsernameToken>
</wsse:Security>';
//push the header into soap
$HeaderObject = new SoapVar( $HeaderObjectXML, XSD_ANYXML );
//push soap header
$header = new SoapHeader( 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd', 'Security', $HeaderObject );
$client->__setSoapHeaders($header);
return $client;
}
public function CreateShippiment($data){
$request = $this->buildCreateshippiment($data);
$type = 'createShipment';
return $this->makerequest($type, $request);
}
public function PrintLabel($shipmentNumber,$order_tracking_id){
$time = gmdate('Y-m-d\TH:i:s');
$request = array(
'integrationHeader' => array(
'dateTime' => $time,
'version' => '2',
'identification' => array(
'applicationId' => $this->apiapplicationid,
'transactionId' => $order_tracking_id
)
),
'shipmentNumber' => $shipmentNumber,
'outputFormat' => 'PDF',
);
$type = 'printLabel';
$response = $this->makerequest($type, $request);
return $response->label;
}
private function makerequest($type, $request){
$client = $this->preparerequest();
$response = false;
$times = 1;
while(true){
try {
$response = $client->__soapCall( $type, array($request), array('soapaction' => $this->locationforrequest) );
// echo "REQUEST:\n" . htmlentities($client->__getLastResponse()) . "\n";
break;
} catch (Exception $e) {
print_r($e);
if($e->detail->exceptionDetails->exceptionCode == "E0010" && $times <= 25){
sleep(1.5);
$times++;
continue;
}else{
echo $e->getMessage();
echo "<pre>";
print_r($e->detail);
echo $client->__getLastResponse();
echo "REQUEST:\n" . htmlentities($client->__getLastResponse()) . "\n";
break;
}
}
break;
}
return $response;
}
private function buildCreateshippiment($data2) {
$time = gmdate('Y-m-d\TH:i:s');
$data = new ArrayObject();
foreach ($data2 as $key => $value)
{
$data->$key = $value;
}
$request = array(
'integrationHeader' => array(
'dateTime' => $time,
'version' => '2',
'identification' => array(
'applicationId' => $this->apiapplicationid,
'transactionId' => $data->order_tracking_id
)
),
'requestedShipment' => array(
'shipmentType' => array('code' => 'Delivery'),
'serviceOccurrence' => 1,
'serviceType' => array('code' => $data->api_service_type),
'serviceOffering' => array('serviceOfferingCode' => array('code' => $data->api_service_code)),
'serviceFormat' => array('serviceFormatCode' => array('code' => $data->api_service_format)),
'shippingDate' => date('Y-m-d'),
'recipientContact' => array('name' => $data->shipping_name, 'complementaryName' => $data->shipping_company),
'recipientAddress' => array('addressLine1' => $data->shipping_address1, 'addressLine2' => $data->shipping_address2, 'postTown' => $data->shipping_town, 'postcode' => $data->shipping_postcode),
'items' => array('item' => array(
'numberOfItems' => $data->order_tracking_boxes,
'weight' => array( 'unitOfMeasure' => array('unitOfMeasureCode' => array('code' => 'g')),
'value' => $data->order_tracking_weight,
)
)
),
//'signature' => 0,
)
);
if($data->api_service_enhancements == 6 && $data->api_service_type == 1){
$request['requestedShipment']['serviceEnhancements'] = array('enhancementType' => array('serviceEnhancementCode' => array('code' => $data->api_service_enhancements)));
}
return $request;
}
}
docs.oasis-open.org is slow and doesn't respond in time.
Download oasis-200401-wss-wssecurity-utility-1.0.xsd and modify ShippingAPI_V2_0_8.wsdl to use local version.
Your location looks wrong..
$soapclient_options['location'] = '****';
Shouldn't this look like this..
$soapclient_options['location'] = 'https://api.royalmail.com/shipping/onboarding';
I'm trying to create a webservice with PHP and nuSoap but everytime I try to execute it I'm getting the error:
XML error parsing SOAP payload on line 1: Not well-formed (invalid token)
Can anyone see what's wrong?
service.php
<?php
require 'lib/nusoap.php';
$server = new nusoap_server();
$server->configureWSDL("casamitger" . "urn:casamitger");
$server->wsdl->schemaTargetNamespace = 'urn:casamitger';
include 'functions.php';
//getAvailabilities
$server->wsdl->addComplexType('Availabilities','complexType','struct','all','',array(
'StartDate' => array('name' => 'StartDate', 'type' => 'xsd:date'),
'EndDate' => array('name' => 'EndDate', 'type' => 'xsd:date'),
'State' => array('name' => 'State', 'type' => 'xsd:string'),
));
$server->wsdl->addComplexType('ArrayOfAvailabilities', 'complexType', 'array', '', 'SOAP-ENC:Array', array(), array(
array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:Availabilities[]')), 'tns:Availabilities');
$server->register(
'getAvailabilities',
array(
"SessionID" => 'xsd:string',
"AccommodationId" => 'xsd:integer'
),
array("return" => 'tns:ArrayOfAvailabilities')
);
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
functions.php
function getAvailabilities($sessionID, $accommodation_code) {
$connection = mysqli_connect("localhost", "root", "", "casamitger");
if (authenticate($sessionID)) {
$user = getUser($sessionID);
$query = mysqli_query($connection, "SELECT count(AccommodationId) c FROM UserAccommodations WHERE AccommodationId = '$accommodation_code' AND CompanyId = '$user'") or die();
$row = mysqli_fetch_object($query);
$count = $row->c;
if ($count > 0) {
$query = mysqli_query($connection, "SELECT StartDate,EndDate,State FROM Availabilities WHERE AccommodationId = '$accommodation_code'") or die();
$n = 0;
while ($row = mysqli_fetch_object($query)) {
$result[$n]['StartDate'] = $row->StartDate;
$result[$n]['EndDate'] = $row->EndDate;
$result[$n]['State'] = $row->State;
$n++;
}
return $result;
}
}
}
and the client.php
<?php
require 'lib/nusoap.php';
include 'functions.php';
$sessionid = '1234';
$accommodation_code = '83081';
$client = new nusoap_client("http://192.168.8.155:8090/ws/service.php?wsdl");
$availabilities = $client->call(
'getAvailabilities',
array(
"SessionID" => "$sessionid",
"AccommodationId" => "$accommodation_code",
)
);
if ($client->fault) {
echo 'Fault';
} else {
$err = $client->getError();
if ($err) {
echo $err;
} else {
print_r($servicetypes);
}
}
?>
If I call the method getAvailabilities() directly it works but it doesn't through the web service, any help will be appreciated, thanks.
I'm starting to learn about web services and I'm doing some tests.
I'm trying to write a service to pass all the data of a table into my client but i can't make it work.
The first one 'servei' works, but the second doesn't.
Any suggestions will be appreciated. Thanks
service.php
require 'lib/nusoap.php';
$server = new nusoap_server();
$server->configureWSDL("test" . "urn:test");
include 'functions.php';
$server->wsdl->addComplexType('servei', 'complexType', 'struct', 'all', '', array(
'preu_antic' => array('name' => 'preu_antic', 'type' => 'xsd:float'),
'preu_actual' => array('name' => 'preu_actual', 'type' => 'xsd:float'),
'descompte_servei' => array('name' => 'descompte_servei', 'type' => 'xsd:float'),
));
$server->wsdl->addComplexType('ServiceTypes', 'complexType', 'struct', 'all', '', array(
'id_tipus_servei' => array('name' => 'id_tipus_servei', 'type' => 'xsd:inter'),
'nom_tipus_servei' => array('name' => 'nom_tipus_servei', 'type' => 'xsd:string'),
'descripcio_tipus_servei' => array('name' => 'descripcio_tipus_servei', 'type' => 'xsd:string'),
));
$server->wsdl->addComplexType('ArrayOfServiceTypes', 'complexType', 'array', '', 'SOAP-ENC:Array', array(), array(
array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:ServiceTypes[]')), 'tns:ServiceTypes');
$server->register('servei', array("id_servei" => 'xsd:inter'), array("return" => 'tns:servei'));
$server->register('getServiceTypes', array("idioma" => 'xsd:string'), array("return" => 'tns:ArrayOfServiceTypes'));
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>
functions.php
function servei($id){
conexio();
$query_servei = mysql_query("SELECT * FROM servei WHERE id_servei = '$id'")or die(mysql_error());
$row = mysql_fetch_array($query_servei);
$preu_antic = $row['preu_antic'];
$preu_actual = $row['preu_actual'];
$descompte_servei = $row['descompte_servei'];
$servei = array('preu_antic'=>$preu_antic,'preu_actual'=>$preu_actual,'descompte_servei'=>$descompte_servei);
return $servei;
}
function getServiceTypes($idioma){
conexio();
$query = mysql_query("SELECT id_tipus_servei, nom_tipus_servei, descripcio_tipus_servei FROM idioma_tipus_servei WHERE id_idioma = '$idioma'") or die(mysql_error());
$n = 0;
while ($row = mysql_fetch_array($query)) {
$result[$n]['id_tipus_servei'] = $row['id_tipus_servei'];
$result[$n]['nom_tipus_servei'] = $row['nom_tipus_servei'];
$result[$n]['descripcio_tipus_servei'] = $row['descripcio_tipus_servei'];
$n++;
}
return $result;
}
?>
client.php
<?php
require 'lib/nusoap.php';
include 'functions.php';
$client = new nusoap_client("http://192.168.8.155:8090/webservice/service.php?wsdl");
//$id=1;
// $servei = $client -> call('servei',array("id_servei"=>"$id"));
// print_r($servei);
$idioma ='ca';
$servicetypes = $client -> call('getServiceTypes',array("idioma"=>"$idioma"));
print_r($servicetypes);
?>
OK, I handled it.
If you are using PHP 5.4 you have to comment line 6132 in nusoap.php.
Couldn't this be fixed if we were to change it from:
$this->debug("serializing array element: $k, $v of type: $typeDef[arrayType]");
To:
$this->debug("serializing array element: $k, $v of type: " . $typeDef['arrayType'] );
The following code is working just fine, but the line $connection->query('call user_create(145552, \'a#a.com\');'); is not creating a user into the database.
function updateFacebook($id) {
$connection = mysqli_connect('localhost', 'root', '', 'databasename');
$count = $connection->query('call user_by_facebook_read(' . $id . ');')->num_rows;
if ($count == 0) {
$request = \Slim\Slim::getInstance()->request();
$body = $request->getBody();
$json = json_decode($body);
$token = $json->token;
$facebook = new Facebook(array(
'appId' => 'value',
'secret' => 'value',
'cookie' => true
));
$facebook->setAccessToken($token);
$facebook->api('/me/feed', 'post', array(
'message' => 'message',
'picture' => 'https://www.google.com.br/images/srpr/logo4w.png',
'link' => 'https://www.google.com.br',
'description' => 'description',
'name' => 'name',
'caption'=> 'caption'
));
$connection->query('call user_create(145552, \'a#a.com\');');
}
$connection->close;
$json = json_encode(array(
'r' => true
));
echo $json;
}
If I run the following code it also works just fine:
$connection = mysqli_connect('localhost', 'root', '', 'databasename');
$connection->query('call user_create(145552, \'a#a.com\');');
$connection->close;
If I close the connection after the $count and open it again before the user_create call it also works.
What is happening?
You need to run ->close() on the result, but you discarded that. So:
$result = $connection->query(..);
$count = $result->num_rows;
$result->close();
and after CALL()s in MySQLi it seems to need this:
$connection->next_result();