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.
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 have a script at Google Script which creates Google Drive directories and is to be activated by API calls, but I fail to make API call to it.
I have deployed the script, bound it to Google Cloud, obtained all credentials for the script and service account. Now I stuck at the point when API call to this script gives me the following error:
Caught exception: json key is missing the type field
$scriptId = env('GOOGLE_SCRIPT_ID');
$service = $this->getService();
$request = new \Google_Service_Script_ExecutionRequest();
$request->setFunction('main');
$request->setParameters("fdf");
try {
$response = $service->scripts->run($scriptId, $request);
if ($response->getError()) {
$error = $response->getError()['details'][0];
printf("Script error message: %s\n", $error['errorMessage']);
if (array_key_exists('scriptStackTraceElements', $error)) {
print "Script error stacktrace:\n";
foreach ($error['scriptStackTraceElements'] as $trace) {
printf("\t%s: %d\n", $trace['function'], $trace['lineNumber']);
}
}
}
} catch (\Exception $e) {
// The API encountered a problem before the script started executing.
echo 'Caught exception: ', $e->getMessage(), "\n";
}
What am I missing? Is there a comprehensive tutorial on this topic? I've read Google's manuals on the topic but they don't work much for me to solve the problem.
I have been trying this for many days but not succeeded. How to make a successful WSDL Soap request to ITR web site.
The sample soap url: https://incometaxindiaefiling.gov.in/e-FilingSecWS/ditsecws/BulkItrService?wsdl
and
The manual which I have refered is: https://incometaxindiaefiling.gov.in/eFiling/Portal/StaticPDF/Secure_WebServices_UserManual.pdf
If any one has any idea please let me know the Steps/Tutorial to successfully make a soap call using PHP apache2 Server, thank you in advance.
You can get a sample code here ..i am trying this.
<?php
ini_set('display_errors',1);
error_reporting(1);
//var_dump($xml);
include('includexml.php');echo '<pre>';
$soapUrl = "https://incometaxindiaefiling.gov.in/e-FilingSecWS/ditsecws/BulkItrService?wsdl";
//Create the client object
$soapclient = new SoapClient("$soapUrl",array('soap_version' => SOAP_1_1));
try {
print($soapclient->uploadBulkItr($includexml));
} catch (SoapFault $exception) {
echo $exception;
}
$res=$soapclient->__getFunctions();
print_r($res);
die;
Im creating a web service (my server is ubuntu vm, not using WAMP or XAMPP) but having an issue = Exception:looks like we got no XML document. I have searched the internet but there are mostly soap exceptions for this, but I am not having a soap fault. It is a plain exception. It is echoing hi, but not echoing hi4, so I guess the problem might be in the function viewHealthDetails (which is in my wsdl) but I am almost sure that my wsdl is correct as I have used it previously in another project. Please help.
if(isset($_POST['txtInput']))
{
try
{
$input=$_POST['txtInput'];
$wsdl='.../Search.wsdl';
$options=array('cache_wsdl'=>WSDL_CACHE_NONE,'features'=>SOAP_SINGLE_ELEMENT_ARRAYS);
$client=new SoapClient($wsdl,$options);
echo "hi";
$response=$client->viewHealthDetails($input);
echo "hi4";
if(isset($response->HealthDetails))
{
$HTMLDocument="<!Doctype html>
// My html code
}
else
{
echo "<h1>This Health type is not in our categories!</h1>";
}
}
catch(Exception $e)
{
echo 'Exception:'.$e->getmessage();
}
catch (SOAPFAULT $exception)
{
echo 'SOAP Exception: '.$exception->getMessage();
}
}
else
{
}
This error is being thrown because the PHP cannot process the response XML correctly. To troubleshoot the response, set your options array to:
$options=array('cache_wsdl'=>WSDL_CACHE_NONE,'features'=>SOAP_SINGLE_ELEMENT_ARRAYS, 'trace' => 1);
then use var_dump($client->__getLastResponse()); after making the request. This will allow you to inspect the returned XML and validate it for correctness. You may find there is other output that is breaking the XML.
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);