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.
Related
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.
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;
When I try to scrape data from some website using say $url using simple html DOM . After few days links get outdated and i get an saying http request failed.So instead of displaying that error.I want to display something else that I want.
For example here is the code :
<?
$html=file_get_html($url);
$title=$html->find("stuff that I want to extract",0)->plaintext;
if($title)
{
echo $title;
}
else{
echo 'problem';
}
?>
In the above example it displays problem only if that data is not found but I need to display problem if I get http request errors too.
error_reporting level is a valid solution. This can throw exceptions and you can use that to handle your errors. There are many reasons why file_get_html might generate warnings, and PHP's manual itself recommends lowering error_reporting.
Or might be this will help you:
$html = file_get_html($url) or die('this is not a valid url');
file_get_html returns false if any issue while getting data.
$html = file_get_html($url);
if ($html) {
// code
} else {
// error
}
Use Try-Catch
try {
$html = file_get_html(trim($url));
} catch (Exception $e) {
// handle error here
}
Suggestion: Use CURL to get the URL and handle the error response.
I'm connecting to a 3rd party service with SoapClient. Most of the time it works fine, but every once in awhile, maybe once out of every 100-150 calls, I get the error
Soap Failed: SOAP-ERROR: Parsing Schema: unexpected in complexType
My code is in a try/catch with a retry, and it will work on the next round through. But I'd like to examine the WSDL to find out why that fails, partly for my own curiosity, and in case I need to pass it along to the company I'm connecting to. Can I get that information from the SoapFault? Or would I have to call the URL to get the string? I'm afraid if I get the WSDL after the fact, it may already be fixed.
$pass = FALSE;
$this->soap = NULL;
$this->session = NULL;
do {
try {
Doc::i("Starting session");
$this->soap = new SoapClient($this->wsdl_url, ['trace' => 1]);
$pass = TRUE;
} catch (\SoapFault $e) {
Doc::e('Soap Failed: ' . $e->getMessage());
if(str_contains($e->getMessage(),'Parsing Schema') && !empty($e->detail)) {
Doc::e($e->detail); // Something new I'm trying to see if it helps
}
} catch (FatalErrorException $e) {
Doc::e("Soap failed really bad: " . $e->getMessage());
} catch (\Exception $e) {
Doc::e("Soap failed bad: " . $e->getMessage());
}
} while (!$pass);
You should be able to use $this->soap->__getLastResponse() since you are passing 'trace' => 1 option to SoapClient.
You might also consider logging $this->soap->__getLastRequest as well as the headers versions of both of these to ensure you're capturing as much information as possible at run-time.
Refer to the SoapClient method list for the possible options. Just remember the trick here is the trace option: without that, these will not return anything useful!
I am trying to access the web service. The below provided code gives the exception message: "Bad Request". Is there any way to see what exactly is wrong in my request? How to debug this code in order to see which parameters in $p are not correct?
try
{
$webServices = $client->queryTest($p);
}
catch (Exception $e) {
print $e->getMessage();
}