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();
Related
Fatal error: Uncaught Error: Call to undefined method MongoDB\Driver\Manager::listDatabases()
this error keep showing when i wanted to use the administration command for mongodb using php. I do not know whats the problem here and someone with kind soul please help me. The following codes is what i have tried which cause that error.
<?php
$client = new MongoDB\Driver\Manager( 'mongodb+srv://'.$_ENV['MDB_USER'].':'.$_ENV['MDB_PASS'].'#'.$_ENV['ATLAS_CLUSTER_SRV'].'/test'
);
try{
$dbs = $client->listDatabases();
echo '<pre>';
print_r($dbs);
echo '</pre>';
// Or Nothing if you just wanna check for errors
}
catch(Exception $e){
echo "Unable to connect to Database at the moment ! ";
exit();
}
$colecciones = $client->listCollections();
foreach ($colecciones as $col) {
echo $col->getName();
}
?>
these two are the refereces that i used but is not working for me
Get collections in mongodb with PHP
Is there a way to test MongoDB connection in PHP?
what i am trying to do here is to make sure that my database connection is successful and also list out the collection name of my mongodb database.`
You are trying to call an undefined method in the MongoDB\Driver\Manager class
You can see the list of methods and functions here
https://www.php.net/manual/en/class.mongodb-driver-manager.php
In addition please follow all the listed function and methods in php mongodb driver.
Try to use this to query data from the database:
$manager = new MongoDB\Driver\Manager('mongodb+srv://'.$_ENV['MDB_USER'].':'.$_ENV['MDB_PASS'].'#'.$_ENV['ATLAS_CLUSTER_SRV'].'/test'
);
$filter = [];
$option = [];
$read = new MongoDB\Driver\Query($filter, $option);
$query = $mongo->executeQuery(‘db.Collection_Name’ $read);
$exportQuery = $query->toArray();
var_dump($exportQuery);
I am trying to learn how to access soap web services via PHP. I can get a list of functions available. I cannot get a return from a SoapClient function. My code is as follows:
<?php
date_default_timezone_set('America/Chicago');
$fcs = 'fcs is initialized';
$url = 'url is initialized';
$res = 'res is initialized';
$url = 'http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL';
$param = array('ZIP' => '72685');
try {
$client = new SoapClient($url);
$fcs = $client->__getFunctions();
$res = $client->GetCityForecastByZIP($param);
} catch (Exception $e) {
echo "<h2>Exception Error!</h2>";
echo $e->getMessage();
}
echo '<br> url = '.$url;
echo '<br> fcs = '.$fcs;
echo '<br> res = '.$res.'<br>';
?>
I have tried about 6 Soap testing URLs that google can find. Some (http://www.webservicex.com/globalweather.asmx?wsdl) of them have evolved into something else. The one I tried the most (http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL) did seem to be having the same trouble I was in it's web page implementation, http://wsf.cdyne.com/WeatherWS/Weather.asmx.
the Exception Error! is
"Server was unable to process request. ---> A network-related or
instance-specific error occurred while establishing a connection to
SQL Server."
To repeat my results,
1) the Soap client object creation seems to work w/o error.
2) __getFunctions seems to work w/o error.
3) trying to get a result from any of the functions produces the error shown above.
Questions:
1) Is there any error in my code that would cause it not to work?
2) What is a good working Soap Web Service URL sandbox?
It looks like its the weather service. To rule out your code go to http://wsf.cdyne.com/WeatherWS/Weather.asmx?op=GetCityWeatherByZIP
Add your ZIP into the Zip box and hit 'Invoke' and you will get an SQL error. So I would say its safe to assume its not your code and its the server.
This is my PHP code
<?php
// Load Azure Drivers
require_once '../vendor/autoload.php';
use WindowsAzure\Common\ServicesBuilder;
use MicrosoftAzure\Storage\Common\ServiceException;
use MicrosoftAzure\Storage\Table\Models\QueryEntitiesOptions;
// Connection String
$connectionString = 'DefaultEndpointsProtocol=https;AccountName=<account_name>;AccountKey=<account_key>==';
// Create table REST proxy.
$tableRestProxy = ServicesBuilder::getInstance()->createTableService($connectionString);
$user_input = "Username eq '<user>'";
try {
$result = $tableRestProxy->queryEntities("<table>", $user_input);
}
catch(ServiceException $e){
echo "<h1>Error querying, please contact Admin.</h1>";
die();
}
$entities = $result->getEntities();
foreach($entities as $entity){
echo $entity;
}
?>
I have censored out all the connection and table information. But everything works when I use the demo code. But I want to retrieve the full row. When I execute this I get this error
Catchable fatal error: Object of class MicrosoftAzure\Storage\Table\Models\Entity could not be converted to string
Any ideas?
Generally speaking, you are trying to echo an object which raised this issue. As the $entity in your looping statement is an object, you cannot directly echo it.
The queryEntities() returns QueryEntitiesResult object, and then you call getEntities() function which returns Entity objects in array.
So you can use functions $entity->getXXXX() or $entity->getPropertyValue({key}) to get the properties in your table storage's entity.
You can refer to a simple sample for a quick glance.
I have a web service available # http://www.xxxxx/zzzzzzzz/service.asmx and I am trying to send a SOAP request for method - some_function with both the parameters but still not able to get the connection through.
This is my code:
<?php
$param = array('cedula'=>'XXXX','contrasena'=>'YYYYYY');
$client = new SoapClient("http://www.xxxxx/zzzzzzzz/service.asmx?wsdl");
$result = $client->__soapCall('some_function', $param);
print $result;
?>
Error that I'm getting is:
Fatal error: Uncaught SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in /home/zzzz/XXXXXXXXXX.com/uni/index.php:6 Stack trace: #0 /home/zzzz/XXXXXXXXXX.com/uni/index.php(6): SoapClient->__soapCall('some_function' , Array) #1 {main} thrown in /home/zzzz/XXXXXXXXXX.com/uni/index.php on line 6
Please suggest the corrections. Many thanks in advance :)
Thanks #dootzky & #lulco. I have solved this. Code below works perfectly fine for me:
<?php
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$wsdl_path = "http://www.xxxxxxx/zzzzzzzzzz/service.asmx?WSDL";
$login_id = 'XXXX';
$password = 'YYYYYY';
$client = new SoapClient($wsdl_path, array('trace' => 1));
try {
echo "<pre>\n";
$result = $client->SOME_FUNCTION(array("request" => array("cedula" => $login_id, "contrasena" => $password)))
print_r($result);
echo "\n";
}
catch (SoapFault $exception) {
echo $exception;
}
?>
I think you are very close to getting this code to work. I would also give credit to this answer on StackOverflow, looks very similar to what you are asking:
"Object reference not set to an instance of an object" error connecting to SOAP server from PHP
So maybe you should just shoot the method directly, like so:
$client->SOME_FUNCTION(array("request" => array('cedula'=>'XXXX','contrasena'=>'YYYYYY'));
Hope that helps! :)
I think it could be problem in wsdl for service SOME_FUNCTION.
Here is the list of services:
http://www.xxxxxx/zzzzzzzzzz/service.asmx
All of them work, but SOME_FUNCTION doesn't. Go to url http://www.xxxxxx/zzzzzzzzzz/service.asmx?op=SOME_FUNCTION and try to set parameters and click Invoke. It will not work and throw exception "Object reference not set to an instance of an object.".
Then try another service, it will work and return some result.
Example for OTHER_FUNCTION service works:
$param = array('estatus'=>'XXXX');
$client = new SoapClient("http://www.xxxxxx/zzzzzzzzzz/service.asmx?wsdl");
$result = $client->__soapCall('OTHER_FUNCTION', $param);
print_r($result);
I'm making what's likely to be a really simple mistake but can't seem to work out. I'm attempting to send a SOAP request to a web service using the PHP SoapClient library. The following error occurs when attempting to print:
"Object of class stdClass could not be converted to string"
Here is the code, taken primarily from the PHP SoapClient Manual.
<?php
try {
$options = array(
'soap_version'=>SOAP_1_2,
'exceptions'=>true,
'trace'=>1,
'cache_wsdl'=>WSDL_CACHE_NONE
);
$client = new SoapClient('http://www.webservicex.net/ConvertTemperature.asmx?WSDL', $options);
$results = $client->ConvertTemp(array('Temperature'=>'100', 'FromUnit' => 'degreeCelsius',
'ToUnit' => 'degreeFahrenheit'));
}
catch (Exception $e)
{
echo "<h2>Exception Error!</h2>";
echo $e->getMessage();
}
$results = $client->ConvertTemp(array('Temperature'=>'100', 'FromUnit' => 'degreeCelsius',
'ToUnit' => 'degreeFahrenheit'));
print $results;
?>
I understand that the message is telling me that I'm trying to print an entire object rather than a member of that object. What I don't understand is that I'm expecting a call to ConvertTemp to return a string. Why is an object being return? Thanks in advance for any help.
Well, your expectations may be wrong. A var_dump or print_r can shed light on what $results actually is, re-examing the wsdl could tell you why:
Hint: __getTypes():
struct ConvertTempResponse {
double ConvertTempResult;
}