PHP - SOAP "Parsing WSDL: Couldn't load from ..." Error - php

This is my code:
$this->options = [
"login" => $username,
"password" => $password
];
try {
$this->request = new SoapClient('https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl', $this->options);
} catch(Exception $e) {
throw new Exception($e->getMessage());
}
And this is the error message:
Fatal error: Uncaught Exception: SOAP-ERROR: Parsing WSDL: Couldn't load from 'https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl' : failed to load external entity "https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl"
Any idea how I can fix this error?
[UPDATE]
I can get functions with this code:
$wsdl = file_get_contents('https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl');
But this code still gets error:
SoapClient('https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl', $this->options);

try from command line:
wget https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl
or
php -r '$a = new SoapClient("https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl"); var_dump($a);'
Maybe resource id not available from tour host

To handle SOAP exceptions, you can give this answer a try. Following code is standalone code which is returning a SOAP response.
$params = array(
"login" => "USERNAME",
"password" => "PASSWORD"
);
try {
$client = new SoapClient('https://servis.turkiye.gov.tr/services/g2g/kdgm/test/uetdsesya?wsdl', array($params));
} catch(Exception $e) {
throw new Exception($e->getMessage());
}
To List all available SOAP functions:
echo " List of available SOAP functions <br/><pre>"; var_dump($client->__getFunctions()); echo "</pre>";
To List all available SOAP types:
echo "List of SOAP types <br/><pre>"; var_dump($client->__getTypes()); echo "</pre>";
This answer has an explanation about how to access any available SOAP function.

Related

SOAP-ERROR: Parsing WSDL: Couldn't load from 'wsdl' : failed to load external entity "wsdl"

$params = array (
"AccountName" => $_POST['comp-name'],
"DBA" => $_POST['DBA'],
"Comment" => $_POST['comments']
);
$options = array(
'soap_version'=>SOAP_1_1,
'trace'=>1,
'exceptions'=>1
);
$context = stream_context_create($options);
try {
$soap = new
SoapClient('https://application.cloud.clickandpledge.com/Signup.svc?wsdl', $options);
$soapParams = array('instruction'=>$params);
$response = $soap->AccountSignUp($soapParams);
}
catch(Exception $e) {
die($e->getMessage());
}
var_dump($response);
I amusing above to code snippet to connect with SOAP using my WSDL file, Where i am getting below error in my screen..
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://application.cloud.clickandpledge.com/Signup.svc?wsdl=wsdl0' : failed to load external entity "http://application.cloud.clickandpledge.com/Signup.svc?wsdl=wsdl0"
You don't seem to have the correct WSDL URL. The one I found is:
https://paas.cloud.clickandpledge.com/PaymentService.svc?wsdl
For your SOAP calls, you would then call the "PaymentService" service. It doesn't look like clickandpledge.com allows a sign-up via SOAP. You probably have to do that via their webpage.
HTH,
Jim

Posting xml to SOAP service

I'm fairly new to SOAP and PHP and I'm having some troubles, that I hope someone here on Stack Overflow can help me with.
I'm trying to use this code to post a xml file (retursvar.xml).
I'm using this code to post the file:
<?php
$url = "https://someserver/somefunction";
$options = array(
'login' => 'someusername',
'password' => 'somepassword',
'trace' => 1
);
$client = new SoapClient($url.'?wsdl', $options);
$document = file_get_contents('retursvar.xml');
$params = array('SubmitDocument' => $document);
$response = $client->__soapCall('submitDocument', $params);
but I get this error in the Apache error log:
PHP Fatal error: Uncaught SoapFault exception: [bpws:forcedTermination] business exception in /var/www/html/soaptest.php:15\nStack trace:\n#0 /var/www/html/soaptest.php(15): SoapClient->__soapCall('submitDocument', Array)\n#1 {main}\n thrown in /var/www/html/soaptest.php on line 15
If i call:
var_dump($client->__getFunctions());
immediately after:
$client = new SoapClient($url.'?wsdl', $options);
I get this output:
array(1) { [0]=> string(62) "SubmitDocumentResponse submitDocument(SubmitDocument $payload)" }
What am I doing wrong?
It says that you haven't caught an exception. Try wrapping your code inside try catch block.

Php SoapClient: SoapFault Exception: Could not connect to host

I make soap requests using this Code :
try {
$S = new \SoapClient($this->wsdl);
$method = 'method';
$params = array('ID' => $Id, 'Code'=> $Code);
return $S->__call($method, $params);
}catch (\Exception $e) {
return $e->getMessage();
}
But an Exception is raised :
SoapFault exception: [HTTP] Could not connect to host
I tried to return all functions described in the WSDL for the Web service
$S = new \SoapClient($this->wsdl);
return $S->__getFunctions();
And I have all functions including my 'method' used above.
What could be the problem?

How do I handle multiple SOAP Faults during php Soap Client request?

I am interested in making a soap call via php’s soapClient to a web service to get the water level from a monitoring station. I want to handle two soapfaults that have occured during the execution. The first fault is as follows :
SoapFault exception: [soapenv:Server.userException] java.rmi.RemoteException: We are sorry, but no data is available from this station at this time in C:\xampp\htdocs\NOAA\LogWriter.php:214 Stack trace: #0 C:\xampp\htdocs\NOAA\LogWriter.php(214): SoapClient->__soapCall('getWaterLevelRa...', Array, Array) #1 C:\xampp\htdocs\NOAA\LogWriter.php(188): getLevel('8531680', '20120726 15:19') #2 {main}
This error is expected to occur several times during the script if the data for a certain time is not available. I need to catch this fault in order to tell the script to try again with a new time. I used a catch block to do so.
I also need to catch a second fault that occurs if the webservice is not loading the wsdl file or the server is timedout. To test for this have gave my script a faultly location to generate the same error I had received previously and it is as follows:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://opendap.co-ops.nos.noaa.gov/axis/services/WaterLevelRawOneMin?wsdl' : Extra content at the end of the document in C:\xampp\htdocs\NOAA\LogWriter.php:210 Stack trace: #0 C:\xampp\htdocs\NOAA\LogWriter.php(210): SoapClient->SoapClient('http://opendap....', Array) #1 C:\xampp\htdocs\NOAA\LogWriter.php(171): getLevel('8531680', '20120726 12:35') #2 {main} thrown in C:\xampp\htdocs\NOAA\LogWriter.php on line 210
The second error remains uncaught and terminates my script. However I need to catch it and display a message.
I have posted my php function that makes the soap call below.
Could anyone give me any ideas on how to do this?
function getLevel($id, $date) {
$client = new SoapClient("http://opendap.co-ops.nos.noaa.gov/axis/services/WaterLevelRawOneMin?wsdl", array('trace' => false));
$Parameters = array("stationId" => $id, "beginDate" => $date, "endDate" => $date, "datum" => "MLLW",
"unit" => 1, "timeZone" => 1);
try {
return $client->__soapCall(
"getWaterLevelRawOneMin", array('Parameters' => $Parameters),
array('location' => "http://opendap.co-ops.nos.noaa.gov/axis/services/WaterLevelRawOneMin")
);
} catch (SoapFault $e) {
if (
$e->faultcode == "soapenv:Server.userException"
and $e->faultstring == "java.rmi.RemoteException: We are sorry, but no data is available from this station at this time"
) {
return "FAULT";
} else {
echo "Could not connect to the server";
}
} // end of catch blocK
}// end of function
Exception regarding broken WSDL can occur only when you call SoapClient::constructor so
try {
$client= new SoapClient($wsdlUrl ,array('trace'=>false));
}catch(Exception $e) {
// your loging regarding this case
}
SoapFault exception can occur when you make a webservice all so:
try {
$client= new SoapClient($wsdlUrl ,array('trace'=>false));
try {
return $client->_call('....');
} catch (SoapFault $sp) {
//your logic rearding soap fault
}
}catch(Exception $e) {
// your loging regarding this case
}
return false;

API resulting in Parsing WSDL: Couldn't load from

I've been at this for the better part of 12 hours now. I keep getting connection issues. This is a non https request, though I have tried enabling the open_ssl.dll and other suggestions.
I can view the WSDL just fine in a browser
http://www.soapclient.com/interop/interopTest.html also returns values for me.
my code:
<?php
function doWebService()
{
########################################################################
# Do some SOAP / Call a Web Service
$soap_url = 'http://WEBSITE/WebServices/PublicAPI.asmx?WSDL';
//$soap_url = 'x.x.x.x/WebServices/PublicAPI.asmx?WSDL';
$sh_param = array(
'username' => 'admin_username',
'password' => 'admin_password');
$soap_client = new SoapClient($soap_url);
$test = $soap_client->Authenticate($sh_param);
echo $test . "\nDone";
/*
try
{
$soap_url = 'http://WEBSITE/WebServices/PublicAPI.asmx?WSDL';
//$soap_url = 'x.x.x.x/WebServices/PublicAPI.asmx?WSDL';
$sh_param = array(
'username' => 'admin_username',
'password' => 'admin_password');
$soap_client = new SoapClient($soap_url);
$test = $soap_client->Authenticate($sh_param);
echo $test . "\nDone";
}
catch (Exception $e)
{
echo "<pre>";
print_r($e);
echo "</pre>";
exit;
}
*/
}
doWebService();
?>
It fails on the $soap_client = new SoapClient($soap_url) line.
I've tried changing between PHP 4.0, 5.2, 5.3. 5.4 and 6.0. None help.
I've tried enabling
extension=php_curl.dll
extension=php_openssl.dll
extension=php_soap.dll
This is on my website using the host:
ntchosting.com
trying to access the API on another.
Actual error code
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://WEBSITE.com/WebServices/PublicAPI.asmx?WSDL' : failed to load external entity "http://WEBSITE.com/WebServices/PublicAPI.asmx?WSDL" in /home/www/MY_WEBSITE.com/main_php/_test_public_api.php:13 Stack trace: #0 /home/www/MY_WEBSITE.com/main_php/_test_public_api.php(13): SoapClient->SoapClient('http://WEBSITE...') #1 /home/www/MY_WEBSITE.com/main_php/_test_public_api.php(50): doWebService() #2 {main} thrown in /home/www/MY_WEBSITE.com/main_php/_test_public_api.php on line 13
All I want to do is be able to use the API to retrieve data and provide a sync between what I've got and another established software. Just does not seem to be remotely easy whenever I try and get my hands wet.
thanks,
jc
I managed to find out that the outbound connections were being blocked. Forced the IP to an allow list and things are working a bit better.

Categories