I'm trying to consume a soap web service using nusoap and PHP 5.6.25 but I am having some errors. Here is the php code:
require_once 'nusoap-0.9.5/lib/nusoap.php';
$client = new nusoap_client('http://www.webservicex.net/ConvertTemperature.asmx?WSDL');
if($client->getError()){
echo 'Error';
} else {
echo 'nusoap is working';
}
Error:
Fatal error: Call to undefined function nusoap_client()
If you check any example on the internet about nusoap_client you can see that it looks like this:
$client = new nusoap_client("food.wsdl", true);
$error = $client->getError();
So when you create a new instances of class nusoap_client you need to add the word new before. So your code will look like this:
$client = new nusoap_client('http://www.webservicex.net/ConvertTemperature.asmx?WSDL');
if($client->getError()){
echo 'Error';
} else {
echo 'nusoap is working';
}
Related
i have php mvc project .
This is my router class.
router class job is include controller in main index page of website.
its work on localhost but when i uploaded on my host not working
what i do ?
<?php
class route
{
function __construct()
{
if(empty($_GET['url']))
{
$url = "index";
}
else
{
$url = $_GET['url'];
}
$url = explode("/",$url);
if(!empty($url[0]))
{
$controllername = "controllers/".$url[0].".php";
if(file_exists($controllername))
{
require($controllername);
$object = new $url[0];
//$object->loadmodel($url[0]);
if(!empty($url[1]))
{
if(method_exists($object,$url[1]))
{
if(!empty($url[2]))
{
$object->$url[1]($url[2]);
}
else
{
$object->$url[1]();
}
}
else
{
echo "Error";
}
}
else
{
echo "Error";
}
}
else
{
echo "Error";
}
}
}
}
this is my error in error_log
thrown in /home/mogeir/public_html/libs/route.php PHP Notice: Array
to string conversion in /home/mogeir/public_html/libs/route.php on
line 33 PHP Notice: Undefined property: admin::$Array in
/home/mogeir/public_html/libs/route.php on line 33 PHP Fatal error:
Uncaught Error: Function name must be a string in
/home/mogeir/public_html/libs/route.php:33
Use the following function call forms instead - the commented ones are correct alternatives too. See call_user_func and call_user_func_array.
if (!empty($url[2])) {
$object->{$url[1]}($url[2]);
// Alternative 1
// call_user_func(array($object, $url[1]), $url[2]);
// Alternative 2
// call_user_func_array(array($object, $url[1]), array($url[2]));
} else {
$object->{$url[1]}();
// Alternative 1
// call_user_func(array($object, $url[1]));
// Alternative 2
// call_user_func_array(array($object, $url[1]), array());
}
You said:
its work on localhost but when i uploaded on my host not working what i do ?
That has to do with the error reporting activation or with difference in PHP version.
I have the following codes copied directly from here:
http://www.codeproject.com/Tips/671437/Creating-Web-Service-Using-PHP-Within-Minutes
Server:
<?php
//call library
require_once ('nusoap.php');
//using soap_server to create server object
$server = new soap_server;
//register a function that works on server
$server->register('get_message');
// create the function
function get_message($your_name)
{
if(!$your_name){
return new soap_fault('Client','','Put Your Name!');
}
$result = "Welcome to ".$your_name .". Thanks for Your First Web Service Using PHP with SOAP";
return $result;
}
// create HTTP listener
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
Client:
<?php
require_once ('nusoap.php');
//Give it value at parameter
$param = array( 'your_name' => 'Cool Guy');
//Create object that referer a web services
$client = new soapclient('http://localhost/SOAPServer.php');
//Call a function at server and send parameters too
$response = $client->call('get_message',$param);
//Process result
if($client->fault)
{
echo "FAULT: <p>Code: (".$client->faultcode."</p>";
echo "String: ".$client->faultstring;
}
else
{
echo $response;
}
?>
When I try to access the client page, it shows me the following error:
FAULT: Code: (SOAP-ENV:Client
String: error in msg parsing: xml was empty, didn't parse!
I would only need this simple example working, what could be the problem?
new to PHP. Using the SLIM framework and the routing has been tested and is working fine. Have two files index.php and API.php. index.php is:
<?php
require 'vendor/autoload.php';
require_once 'API.php';
//Turn on error checking
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
//Create a new SLIM app
$app = new \Slim\Slim();
$app->response->headers->set('Content-Type', 'application/json');
$app->get('/', function() use($app) {
$app->response->setStatus(200);
echo "InstaAPI\n";
});
$app->run();
?>
API is:
<?php
class DbHandler{
protected static $conn;
function __construct() {
//Static self notation is different
if(!isset(self::$conn)) {
//same as self.connect
$this->connect();
}
}
function __destruct(){
if(isset(self::$conn)){
self::$conn->close();
}
}
function connect(){
$config = parse_ini_file('../../config2.ini');
// Try and connect to the database
self::$conn = mysqli_connect('localhost',$config['username'],$config['password'],$config['dbname']);
if(self::$conn===FALSE) {
header("HTTP/1.1 500 Internal Server Error");
header("Content-Type: application/json");
$response = array("Response"=>"Failed to connect to the database");
echo json_encode($response);
die();
}
else{
echo "Fine!!";
}
}//end connect
}//end class
?>
I am getting the error: PHP Fatal error: Cannot redeclare class DbHandler in ../API.php on line 62. Not sure why this is happening. I am using require_once and still getting the same error. Could someone give me some pointers to what I might be doing wrong please?
the code of Api.php is less than 62 lines. looks like there is extra code below it. consider deleting extra lines
I am trying to access this web service and it is working fine but when i come to diplay the results using the TopGoalScorersResult it is giving me this error "Catchable fatal error: Object of class stdClass could not be converted to string". Can anyone please help me with this. The $results variable is filled with the correct answers just want to display them using the method TopGoalScorersResult
<?php
try {
$client = new SoapClient(
'http://footballpool.dataaccess.eu/data/info.wso?wsdl');
var_dump($client->__getFunctions());
var_dump($client->__getTypes());
$results = $client->TopGoalScorers(array("iTopN"=>"20"));
var_dump($results);
echo $results->TopGoalScorersResult;
} catch (SoapFault$e) {
echo "<pre>" . $e->getMessage() . "</pre>";
}
?>
web services in php4 you can use SOAP on the WSDL to call the web-service functions exmaple link is hereenter link description here
$client = new SoapClient("youridSome.wsdl");
and now $client is now an object . There was a method called getTime() in the WSDL then you use
$result = $client->getTime();
I'm Using PHP Soap Client function to connect Remote service using this code
try
{
$result = $soapClient->GetData($parameters);
}
catch (SoapFault $fault)
{
echo "Fault code: {$fault->faultcode}" . NEWLINE;
echo "Fault string: {$fault->faultstring}" . NEWLINE;
if ($soapClient != null)
{
$soapClient = null;
}
exit();
}
$soapClient = null;
Finally I'm calling this function,
echo "Return value: {$result->GetDataResult}" . NEWLINE;
But It's not working for me and got warning message like this.
Notice: Undefined property: stdClass::$GetDataResult
You are ASSUMING that the response comes as an object with the property "GetDataResult". What makes you think so? This is not the case, and that's why you get this error message.
Dump the content of $result to see what you really get. You can also look at the WSDL file to see what the service promises to respond with.