In PHP 5 you can use SoapClient on the WSDL to call the web service functions. For example:
$client = new SoapClient("some.wsdl");
and $client is now an object which has class methods as defined in some.wsdl. So if there was a method called getTime in the WSDL then you would just call:
$result = $client->getTime();
And the result of that would (obviously) be in the $result variable. You can use the __getFunctions method to return a list of all the available methods.
Answer from davidmytton on Stack OverflowIn PHP 5 you can use SoapClient on the WSDL to call the web service functions. For example:
$client = new SoapClient("some.wsdl");
and $client is now an object which has class methods as defined in some.wsdl. So if there was a method called getTime in the WSDL then you would just call:
$result = $client->getTime();
And the result of that would (obviously) be in the $result variable. You can use the __getFunctions method to return a list of all the available methods.
I've had great success with wsdl2php. It will automatically create wrapper classes for all objects and methods used in your web service.
Videos
You can create a very simple JSON/JSONP API without libraries.
Here's a very basic example where you'd take an array of data, then JSON encode that array and returns the JSON, or JSONP, depending on the request:
$data = array();
//....do something to prepare your data....
if(isset($_GET['callback'])) {
$callback = preg_replace("/[^A-Za-z0-9\.]/", '', $_GET['callback']);
header("Content-type: application/javascript");
echo $callback . "(" . json_encode($data) . ");";
}
else{
header("Content-type: application/json");
echo json_encode($data); //JSON
}
This is a great tutorial when i start writing my own web service. David Walsh FTW!
It uses PHP/MySQL with outputs being in JSON and/or XML