I am new to the programming area and this is my first nusoap-0.9.5 client and server program. Although the the server looks correct the client keeps giving me this warning:
PHP Fatal error: SoapClient::SoapClient(): Invalid parameters in /var/www/client.php on line 5
PHP Fatal error: Uncaught SoapFault exception: [Client] SoapClient::SoapClient(): Invalid parameters in /var/www/client.php:5
Stack trace:
#0 /var/www/client.php(5): SoapClient->SoapClient('http://localhos...', true)
#1 {main}
thrown in /var/www/client.php on line 5
Anybody knows the reason? I am trying to find a solution over the net more than a week now and I can not understand what is wrong with my program why it is not working.
Client code:
Thanks again Davey, I have read all the tutorials that you recommend and I am still a bit confused but at least less confused than before. I have modified my code again, I hope it makes more sense now. So here it is:
<?php
include "conf_client.php";
require_once('nusoap.php');
$client = new soapclient('http://localhost:8048/server.php?wsdl',true);
class Data {
public $acro = acro;
public $note = note;
public $prio = prio;
public $date = date;
public function Delete() {
$create = array ($acro,
$date,
$note,
$prio);
return $create;
}// End of Function Delete
}// End of class Data
$data = new Data();
$delete = $data->Delete();
$response = $client->call('Lists.DeleteToDo',$delete);
var_dump($response);
?>
directory: {file:///var/www/server.php}
Any help is much appreciated.
'List.DeleteToDo'
Is the class: List and the Function: DeleteToDo on the side of the server that I am calling.
I manage to find more about my problem and I have solved it. I am posting my server code here maybe it can help also someone else.
As a beginner I have simplified the code as much as possible. I am not including to my answer the configuration file, but if anybody needs it please let me know and I will post it as well.
I would also like to say thank you to everyone who answered my query at this forum and help me understand my errors.
<?php
include "conf.php";
require_once('nusoap/lib/nusoap.php');
$server = new soap_server();
$server->configureWSDL('This is my First nuSoapServer', 'urn:nuSoapServer');
$server->wsdl->addComplexType('Data',
'compexType',
'struct',
'all',
'',
array('id' => array('name' => 'id', 'type' => 'xsd:int'),
'acro' => array('name' => 'acro', 'type' => 'xsd:string'),
'time' => array('name' => 'time', 'type' => 'xsd:string'),
'date' => array('name' => 'date', 'type' => 'xsd:string'),
'note' => array('name' => 'note', 'type' => 'xsd:string'),
'prio' => array('name' => 'prio', 'type' => 'xsd:int'),
'data' => array('name' => 'data', 'type' => 'xsd:string')
)
);
$server->wsdl->addComplexType(
'DataArray', // Name
'complexType', // Type Class
'array', // PHP Type
'', // Compositor
'SOAP-ENC:Array', // Restricted Base
array(), // Elements
array( // Atributes
array('ref' => 'SOAP-ENC:arrayType',
'wsdl:arrayType' => 'tns:Data[]')
),
'tns:Data'
);
$server->register('GetTodoList', // method name
array('acro' => 'xsd:string'), // input parameters
array('DataResult' => 'tns:DataArray'), // output parameters
'urn:nuSoapServer', // namespace($namespace)
'urn:nuSoapServer#GetTodoList', // soap action
'rpc', // style
'encoded', // use
'Return Get to do list'); // documentation
function GetMyConnection() {
global $InputArray;
$dbase_link = mysql_connect($InputArray['host'],$InputArray['mysql_user'],$InputArray['mysql_password']);
//check if connected
if (!$dbase_link) {
die("Can not connect: " . mysql_error());
}
//return $this->myconn;
//http://se1.php.net/manual/en/function.mysql-create-db.php
$dbase_select = mysql_select_db($InputArray['mysql_dbase']);
if (empty($dbase_select)) {
$sql = "CREATE DATABASE IF NOT EXISTS ".$InputArray['mysql_dbase']."\n";
if (mysql_query($sql)) {
echo "Database: " . $InputArray['mysql_dbase'] . " was created succesfully\n";
}
else {
echo "Error creating database: " . mysql_error() . "\n";
}
}
$dbase_select = mysql_select_db($InputArray['mysql_dbase']);
$sql = "CREATE TABLE IF NOT EXISTS ".$InputArray['mysql_dbase_table']." (
`id` int(11) NOT NULL AUTO_INCREMENT,
`acro` varchar(25) NOT NULL,
`time` varchar(25) NOT NULL,
`date` varchar(25) NOT NULL,
`note` varchar(1024) NOT NULL,
`prio` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1";
$create = mysql_query($sql);
if (!$create) {
echo "Error creating table: " . mysql_error() . "\n";
}
}// End of Function GetMyConnection
function closeConnection() {
$terminate = mysql_close();
if ($terminate) {
echo "Connection terminated\n";
}
else {
echo "Error terminating connection: " . mysql_error() . "\n";
}
}//End of function closeConnection
// create the function
function GetTodoList($acro) {
global $InputArray;
GetMyConnection();
if (!$acro) {
return new soap_fault('Client', '', 'No data received!');
}
else {
$dbase_select = mysql_select_db($InputArray['mysql_dbase']);
$get = mysql_query("SELECT * FROM " . $InputArray['mysql_dbase_table'] . " WHERE `acro` = '" . $acro . "'");
if($get === FALSE) {
echo "Could not retrieve data from: " . $InputArray['mysql_dbase_table'] . " due to: " . mysql_error() . "\n";
}
else {
while($total = mysql_fetch_array($get)) {
$Data[] = array('id' => $total['id'],
'acro' => $total['acro'],
'time' => $total['time'],
'date' => $total['date'],
'note' => $total['note'],
'prio' => $total['prio']);
}
}
}
return $Data;
closeConnection();
}
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
Your URL for the SOAP is trying to access a local file path rather than a URL
If you open the URL you've specified in a browser you should get back a (possibly large) chunk of XML. I can almost guarantee that you would get nothing apart from a 404 error
For the SOAP connection you have to use the URL specified by the webserver rather than a local file path (unless you replace http:// with file:/// - that may work).
If your webserver exposes a URL (e.g., http://localmachine) and the WSDL is hosted in a subfolder (e.g., soapstuff) then the URL you would need to enter into the $client=new soapclient line would be something like http://localmachine/soapstuff?wsdl
Related
I'm trying to create a ad via the Facebook Business SDK. Everything works well until I'm trying to create a AdCreativeVideoData. Code:
protected function createAdVideoCreative($thumbnail_url, $video_id, $name){
$video_data = new AdCreativeVideoData();
$video_data->setData(array(
AdCreativeVideoDataFields::IMAGE_URL => $thumbnail_url,
AdCreativeVideoDataFields::VIDEO_ID => $video_id,
AdCreativeVideoDataFields::CALL_TO_ACTION => array(
'type' => AdCreativeCallToActionTypeValues::LIKE_PAGE,
'value' => array(
'page' => FbAds::PAGE_ID,
),
),
));
$object_story_spec = new AdCreativeObjectStorySpec();
$object_story_spec->setData(array(
AdCreativeObjectStorySpecFields::PAGE_ID => FbAds::PAGE_ID,
AdCreativeObjectStorySpecFields::VIDEO_DATA => $video_data,
));
$creative = new AdCreative(null, FbAds::AD_ACCOUNT_ID);
$creative->setData(array(
AdCreativeFields::NAME => $name,
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));
try {
$creative->create();
return $creative;
} catch (Exception $e) {
print("Create Ad Video Creative Exception: " . $e->getMessage() . " (" . $e->getCode() . ")");
exit;
}
}
The above method is called when the selected video is uploaded to Facebook via the following method:
protected function createAdVideo($video_path){
$video = new Advideo(null, FbAds::AD_ACCOUNT_ID);
$video->{AdVideoFields::SOURCE} = $video_path;
try {
$video->create();
return $video->{AdVideoFields::ID};
} catch (Exception $e) {
print("Create Ad Video Exception: " . $e->getMessage() . " (" . $e->getCode() . ")");
exit;
}
}
The problem is that when I'm trying to create the AdCreativeVideoData, the following error is thrown:
[message] => Invalid parameter
[type] => OAuthException
[code] => 100
[error_subcode] => 1885252
[is_transient] =>
[error_user_title] => Video not ready for use in an ad
[error_user_msg] => The video is still being processed. Please wait for the video to finish processing before using it in an ad.
[fbtrace_id] => AwW0d9+Piz1
As you can see, the video is not yet processed. My question is: how can I check the status of the video? Is there a endpoint available somewhere which I can ping to check the status? The documentation states that I can check the status, but the AdVideo object in the createAdVideo() method doesn't have a status field:
I'm at a loss here so I hope someone can shed a light on this problem. Thanks in advance!
AdVideo does not have a status field since then, but Video does: https://developers.facebook.com/docs/graph-api/reference/video
Internally it's the same id, so you can request https://graph.facebook.com/v4.0/{video-id}?fields=id,status which will return the status of the uploaded (Ad)Video.
I'll assume it is because the video is not uploaded at all.
Instead of using "source" try using "file_url". You may also want to add a parameter "title" so it will not be named untitled video- but it is not required.
And try using the SDK smarter like so:
$myVideoUpload = (new AdAccount("act_123456676"))-
>createAdVideo(
array() //fields
array( //params
"file_url"=>"http://whatever.com",
"title"=>"my title"
)
);
if this works, it'll return a json_encodes string with id=video_id.
If you want to be able to retrieve errors- if any- and a general method for all api calls, do use the graph api as such:
$fb = new Facebook(array(
"app_id"=>"blalaa",
"app_secret"=>"blaaaaa",
"default_graph_version"=>"v9.0"
));
$url = "/act_123456789/advideos";
$access_token = "my token";
$params =
array("file_url"=>"https://whatever.com","title"=>"some video");
try{
$response = $fb->post(
$url,
$params,
$access_token
)
$response = $response->getGraphNode();
} catch(FacebookResponseException $e) {
return "graph error:: " . $e->getMessage();
} catch(FacebookSDKException$e) {
return "sdk error:: " . $e->getMessage();
}
The last one can be applied to everything given that you have an access_token that has access to the specific edge that you are requesting thus only he URL needs to be changed accordingly along with the parameters.
Note:
While using the graph-api: Use POST if you want to change or create something, and GET if you only want to read.
I am working on this legacy system that needs to maintain its SOAP service, and I am currently trying to integrate it with codeigniter, keeps giving me an error XML error parsing SOAP payload on line 70: Reserved XML Name. I have tried the trim solution that someone mention and that did not work. It does not give me this error with normal arrays. Only multidimensional arrays. Any advice would be appreviated
<?php
class Employee_Trainings_Soap extends MY_Controller {
public function __construct() {
parent::__construct();
$this->load->library("Soap_lib");
$this->nusoap_server = new soap_server();
}
public function employee_detail() {
$namespace = 'http://localhost/employee_trainings_soap/employee_detail?wsdl';
$this->nusoap_server->debug_flag = true;
$this->nusoap_server->configureWSDL('EmployeeTrainings', $namespace);
$this->nusoap_server->wsdl->schemaTargetNamespace = $namespace;
$this->nusoap_server->wsdl->addComplexType('response', 'complexType', 'struct', 'all', '', array(
"validOPIN" => array(
"name" => "valid_OPIN",
"type" => "xsd:string"
),
"message" => array(
"name" => "message",
"type" => "xsd:string"
)
));
$this->nusoap_server->wsdl->addComplexType('responses', 'complexType', 'array', '', 'SOAP-ENC:Array', array(), array(
array(
"ref" => "SOAP-ENC:arrayType",
"wsdl:arrayType" => "tns:response[]"
)),
"tns:response"
);
$this->nusoap_server->register('getEmployeeTrainings', array("id" => "xsd:string"), array('test'=>'tns:responses'),
$namespace, $namespace."#getEmployeeTrainings", "rpc", "encoded",
'Use this service to list notaries connected to the signed-in title company.'
);
function getEmployeeTrainings($id) {
$data = array();
$data[] = array('valid_OPIN'=>'test','message'=>'test2');
$data[] = array('valid_OPIN'=>'test','message'=>'test2');
//$data = array('valid_OPIN'=>'test','message'=>'test2');
return array('test'=>$data);
}
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
$this->nusoap_server->service($POST_DATA);
}
function live_client_test() {
$this->soapclient = new nusoap_client('http://localhost/employee_trainings_soap/employee_detail');
$err = $this->soapclient->getError();
if ($err) {
echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
}
$result = $this->soapclient->call('getEmployeeTrainings', array('id' => 'test'));
if ($this->soapclient->fault) {
echo '<h2>Fault</h2><pre>';
print_r($result);
echo '</pre>';
} else {
$err = $this->soapclient->getError();
if ($err) {
echo '<h2>Error</h2><pre>' . $err . '</pre>';
} else {
// Display the result
echo '<h2>Result</h2><pre>';
print_r($result);
echo '</pre>';
}
}
}
}
So I have found the issue, this may not be the only solution, it is the solution that we found that worked for us. We had to take the SOAP Service out of Code Igniter for it to work. The moment that we took the service outside of Code Igniter, it worked. This may be a bug with code igniter or it could have been with the way we were using it, but as a quick solution it worked. Additionally, we also found it worked better on a Linux dev box compared to an XAMPP dev box. I hope this helps anyone else that might have the same issue.
I'm really stuck on this one. At the bottom of this post, I've attached the API documentation I'm working with. I want to catch the "message" when the response ("ask") isn't "Success". Seems reasonable enough, right? But when I do something like:
sfcSendError('Something went wrong. This is the message from the API: ' . $result->message);
I get a fatal error:
PHP Fatal error: Cannot access protected property SoapFault::$message
I found this seemingly related question on SO, so I tried changing "message" to "getMessage()" but (no surprise) that results in a different fatal error about calling an undefined function.
Here's my code snippet:
$client = mySoapClient(MODULE_SHIPPING_SFC_API_URL);
if (!$client) {
sfcSendError('could not make a SOAP connection. Halting until next CRON. [' . __FILE__ . ':' . __LINE__ . ']', 'SOAP Failure in cron job');
exit; //halt and wait for the next time cron runs
} else {
$HeaderRequest = array(
'customerId' => MODULE_SHIPPING_SFC_ACCOUNT,
'appToken' => MODULE_SHIPPING_SFC_TOKEN,
'appKey' => MODULE_SHIPPING_SFC_KEY
);
$reg = array(
'HeaderRequest' => $HeaderRequest,
'detailLevel' => 1,
'ordersCode' => $_query->fields['sfc_ordersCode']
);
$result = $client->getOrderByCode($reg);
if ($result->ask != "Success") {
sfcSendError('Something went wrong. This is the message from SFC: ' . $result->message, 'SOAP Failure in cron job');
$_query->MoveNext();
continue;
}
}
This is the referenced function:
function mySoapClient($url)
{
try {
$client = #new SoapClient($url, array(
'trace' => 1,
'exceptions' => 0,
'encoding' => 'UTF-8'
));
} catch (SoapFault $e) {
return 0;
}
return $client;
}
What am I doing wrong? Or is this a "bug" with the API where they really shouldn't be using "message" in their response?
I am trying to integrate bigbluebutton into Codeigniter and after complete set i am not able to create meeting and other things.. below is the code
<?php
// Require the bbb-api file:
require_once('../includes/bbb-api.php');
// Instatiate the BBB class:
$bbb = new BigBlueButton();
/* ___________ CREATE MEETING w/ OPTIONS ______ */
/*
*/
$creationParams = array(
'meetingId' => '1234', // REQUIRED
'meetingName' => 'Test Meeting Name', // REQUIRED
'attendeePw' => 'ap', // Match this value in getJoinMeetingURL() to join as attendee.
'moderatorPw' => 'mp', // Match this value in getJoinMeetingURL() to join as moderator.
'welcomeMsg' => '', // ''= use default. Change to customize.
'dialNumber' => '', // The main number to call into. Optional.
'voiceBridge' => '', // PIN to join voice. Optional.
'webVoice' => '', // Alphanumeric to join voice. Optional.
'logoutUrl' => '', // Default in bigbluebutton.properties. Optional.
'maxParticipants' => '-1', // Optional. -1 = unlimitted. Not supported in BBB. [number]
'record' => 'false', // New. 'true' will tell BBB to record the meeting.
'duration' => '0', // Default = 0 which means no set duration in minutes. [number]
//'meta_category' => '', // Use to pass additional info to BBB server. See API docs.
);
// Create the meeting and get back a response:
$itsAllGood = true;
try {$result = $bbb->createMeetingWithXmlResponseArray($creationParams);}
catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
$itsAllGood = false;
}
if ($itsAllGood == true) {
// If it's all good, then we've interfaced with our BBB php api OK:
if ($result == null) {
// If we get a null response, then we're not getting any XML back from BBB.
echo "Failed to get any response. Maybe we can't contact the BBB server.";
}
else {
// We got an XML response, so let's see what it says:
print_r($result);
if ($result['returncode'] == 'SUCCESS') {
// Then do stuff ...
echo "<p>Meeting succesfullly created.</p>";
}
else {
echo "<p>Meeting creation failed.</p>";
}
}
}
?>
And what parameters have to pass to create meeting in url
I am developing an SMS Based Registration System and so far I'm at the stage of testing my system. All of a sudden, I was not able to receive any messages from my server when I tried to register via SMS it must receive a confirmation messages. Here's what i did when using PHP nusoap.
Register.php
<?php
// This will allow user to register via SMS.
error_reporting( E_ALL );
// load the nusoap libraries. These are slower than those built in PHP5 but
require_once('nusoap.php');
// create the client and define the URL endpoint
$soapclient = new nusoap_client('http://www.mnccyf.info/soap_book.php?wsdl');
// set the character encoding, utf-8 is the standard.
$soapclient->soap_defencoding = 'UTF-8';
$soapclient->call('sendSMS', array( 'uName' => '48dwi5',
'uPin' => '159597',
'MSISDN' => '09152886810',
'messageString' => 'Registered Successfully',
'Display' => '1',
'udh' => '',
'mwi' => '',
'coding' => '0' ),
"http://ESCPlatform/xsd");
?>
Inquiry.php
<?php
// This will allow user to inquire about the latest news within the organization.
error_reporting( E_ALL );
// load the nusoap libraries. These are slower than those built in PHP5 but
require_once('nusoap.php');
$soapclient = new nusoap_client('http://www.mnccyf.info/soapquery_server.php?wsdl');
// set the character encoding, utf-8 is the standard.
$soapclient->soap_defencoding = 'UTF-8';
// Call the SOAP method, note the definition of the xmlnamespace as the third in the call and how the posted message is added to the message string
$soapclient->call('sendSMS', array( 'uName' => '48dwi5',
'uPin' => '159597',
'MSISDN' => '09152886810',
'messageString' => 'Summer Camp 2013',
'Display' => '1',
'udh' => '',
'mwi' => '',
'coding' => '0' ),
"http://ESCPlatform/xsd");
?>
incoming_sms.php
<?php
require_once('nusoap.php');
function sendSMS($number,$soapclient)
{
$x=sendSMS("09152886810",$soapclient);
}
# Load XML string from input
$xml = simplexml_load_file('php://input');
# Parse the XML for parameters
$sms = array();
$nodes = $xml->xpath('/message/param');
foreach($nodes as $node)
{
$param = (array) $node;
$sms[$param['name']] = $param['value'];
}
if($sms['messageType'] == 'SMS-NOTIFICATION') {
sendSMS();
list($action, $messagetype, $source, $type) =explode (" ",$soapclient);
}elseif($sms['messageType'] == 'SMS') {
sendSMS();
list($action, $name, $age, $localchurch, $district) = explode(" ",$soapclient);
}elseif($sms['messageType'] == 'SMS') {
sendSMS();
list($action, $event,$location,$time) = explode(" ", $soapclient);
}
else {
echo "Unsupported Message Type";
}
?>
register_soapserver.php
<?php
//call library
require_once ('nusoap.php');
//using soap_server to create server object
$server = new nusoap_server;
$server ->configureWSDL('http://iplaypen.globelabs.com.ph:1881/axis2/services/Platform?
wsdl','urn:http://iplaypen.globelabs.com.ph:1881/axis2/services/Platform?wsdl');
//register a function that works on server
$server->register('reg');
// create the function
function reg()
{
$connect = mysql_connect("localhost","root","jya0312#");
if (!$connect)
{
die("Couldnt connect" . mysql_error());
}
mysql_select_db("cyfdb", $connect);
$sql = "INSERT INTO mydb(name, age,localchurch,district) VALUES ('{$_POST [name]}','{$_POST[age]}','{$_POST[localchurch]}','{$_POST[district]}')";
mysql_close($connect);
}
// create HTTP listener
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
soapquery_server.php
<?php
//call libraryrequire_once ('nusoap.php');
//using soap_server to create server object
$server = new nusoap_server;
$server ->configureWSDL('http://iplaypen.globelabs.com.ph:1881/axis2/services/Platform? wsdl','urn:http://iplaypen.globelabs.com.ph:1881/axis2/services/Platform? wsdl');
//register a function that works on server
$server->register('getquery');
// create the function
function getquery()
{
$link=mysql_connect("localhost", "root", "jya0312#") or die("Cannot connect to DB!");
mysql_select_db("cyfdb") or die("Cannot select DB!");
$sql = "SELECT event,location,time from activity";
while($r = mysql_fetch_array($sql)){
$items[] = array('event'=>$r['event'],
'location'=>$r['location'],
'date'=>$r['date']);
}
return $items;
$mysql_close($link);
}
// create HTTP listener
$server->service($HTTP_RAW_POST_DATA);
exit();
?>