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);
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 am trying to write a code for sso login with crowd in my custom php application. I trying to to do that with SOAP. I am in a early stage now and was going through the documentation of how to connect php soap with wsdl. But i seem to be stuck very deep as i dont know what should be done next.
<?php
class test {
function authenticateApplication()
{
$client = new SoapClient("http://localhost:8095/crowd/services/SecurityServer?wsdl");
$param = array('in0' => array('credential' => 'password','name' => 'app'));
$resp=$client->authenticateApplication($param);
$token = $resp->out->token;
print_r($resp);
}
}
$t= new test;
$t->authenticateApplication();
I Dont know whats wrong with this code. I have referred it online and it seems to be correct but when i am tring to run this program i am getting this error
Fatal error: Uncaught SoapFault exception: [soap:Client] The validated object is null in /var/www/html/badebade/soaptest.php:7 Stack trace: #0 /var/www/html/badebade/soaptest.php(7): SoapClient->__call('authenticateApp...', Array) #1 /var/www/html/badebade/soaptest.php(7): SoapClient->authenticateApplication(Array) #2 /var/www/html/badebade/soaptest.php(13): test->authenticateApplication() #3 {main} thrown in /var/www/html/badebade/soaptest.php on line 7
A little help will be much appreciated as this program authenticates the application in crowd wsdl and returns the token. Can someone help me to achieve it.
function Find($request) {
try {
$soapClient = new SoapClient('wsdl.wsdl', array('trace' => 1));
$results = $soapClient->authenticateApplication($request);
return $results;
}
catch(SoapFault $ex) {
print $ex->getMessage();
echo '<HR>';
print $ex->getTraceAsString();
echo '<HR>';
echo $ex->getLine();
}
}
$results = Find($params);
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 am using SoapClient but I am not able to get the result. I get this error:
The server was unable to process the request due to an internal error.
For more information about the error, either turn on
IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute
or from the configuration behavior) on the server in order to send the
exception information back to the client, or turn on tracing as per
the Microsoft .NET Framework 3.0 SDK documentation and inspect the
server trace logs.
<?php
$silverpop = new SoapClient($my_url, array('trace' => 1));
/*$client = new stdClass();
$client->LoginID = 'mylogin-id';
$client->LicenceKey = 'mylicense-key';*/
$clientobj = (object) array("LoginID" => "mylogin-id", "LicenceKey" => "mylicense-key");
try {
//$var = $silverpop->__soapCall("GetServicesforPincode",array('P_Pincode'=>'110014','P_ClientObject'=>$clientobj));
//$var = $silverpop->GetServicesforPincode('110014',$clientobj);
$var = $silverpop -> __soapCall("GetServicesforPincode", array('110014', $clientobj));
} catch (SoapFault $exception) {
echo $exception -> getMessage();
}
echo '<pre>';
print_r($var);
?>
What am I doing wrong?
Either you have send your data not according to the specifications or your SoapServer is not working. I think the first one as Soap isn't always as clear as it should. As it looks like the error message is actually generated by the SoapServer, I recommend checking the schema for allowed parameters/calls and their format. If that's all correct, check if you are missing headers etc.
If all of the above is correct, fix your SoapServer. If you haven't gotten access to it, poke the owner.
try{
$client = new SoapClient($my_url,array('trace' => 1));
$object = new stdClass();
$object->LoginID = 'mylogin-id';
$object->LicenceKey = 'mylicense-key';
$xml = simplexml_load_string($client->GetServicesforPincode($object));
$json = json_encode($xml);
print_r($json);
}
catch (SoapFault $exception) { echo $exception; }
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;
}