Jump to content

PHP soap


dizzy1

Recommended Posts

The "soap call function" seems not be called, can someone tell me where if thier is such a thing as a "soap call function" and where i can find it, to include it.

 

stockclient.php

<?php

require_once('nusoap/lib/nusoap.php');

$c = new soapclient('http://www.eximiusdesigns.co.uk/soap/stockserver.php?wsdl');

$stockprice = $c->call('getStockQuote',
        array('symbol' => 'ABC'));

echo "The stock price for 'ABC' is $stockprice. <br> <br>";


?>

 

Quite simple and straight forward how ever i get this error when i run stockclient.php :

 

 

Fatal error: Uncaught SoapFault exception: [Client] Function ("call") is not a valid method for this service in C:\xampp\htdocs\soap\stockclient.php:8 Stack trace: #0 [internal function]: SoapClient->__call('call', Array) #1 C:\xampp\htdocs\soap\stockclient.php(8): SoapClient->call('getStockQuote', Array) #2 {main} thrown in C:\xampp\htdocs\soap\stockclient.php on line 8

 

 

Link to comment
https://forums.phpfreaks.com/topic/194274-php-soap/
Share on other sites

The error you are getting is happening because the method you are trying to use in the service does not exist. I attempted to look at the wsdl but found no valid service exists at that url.

 

So either the service is not up or the method you are calling 'getStockQuote', is not a valid method for that service.

 

Good luck.

Link to comment
https://forums.phpfreaks.com/topic/194274-php-soap/#findComment-1022131
Share on other sites

  • 2 weeks later...

Thought I would just use this thread rather than start a new one as its along the same lines. Is it possible to have PHP check to see if a method exists for a webservice. i.e.

 

$test = new SoapClient("file.wsdl");

if(method_exists($test, "someMethod"))
{
    echo "GOOD";
}
else
{
    echo "BAD";
}

 

I had a go with the method_exists function, but it seems to return false if it exists or not. Thanks for the help

Link to comment
https://forums.phpfreaks.com/topic/194274-php-soap/#findComment-1028271
Share on other sites

Since your error included an exception message, you must be on PHP5.

 

Therefore you can use exceptions to determine if the method exists or not.

 

<?php
try {
  $exists = true;
  $c->call('doesThisMethodExist', array('symbol' => 'ABC'));
} catch( Exception $ex ) {
  $exists = strpos( $ex->getMessage(), 'Function ("doesThisMethodExist") is not a valid method for this service' ) === false;
}
?>

 

I whipped that up on the fly so while the concept should be sound, the code may not be right.

 

That method is a little out of the way; this might be easier:

http://www.php.net/manual/en/soapclient.getfunctions.php

 

Or poke around in the SOAP documentation:

http://www.php.net/manual/en/book.soap.php

Link to comment
https://forums.phpfreaks.com/topic/194274-php-soap/#findComment-1028294
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.