I need some clear code examples for the creation of the web service and the client.
In the answere I put some examples and the url of the page where you can found more explained the question, is an excelent reference for the junior programers.
I need some clear code examples for the creation of the web service and the client.
In the answere I put some examples and the url of the page where you can found more explained the question, is an excelent reference for the junior programers.
I found this article to explain easy how to create a WS service and client in PHP, the url is the next:
http://thenullpointerexceptionx.blogspot.mx/2016/05/crear-web-services-con-php-y-soap-basico.html
The example code is:
Server:
<?php
require_once "nusoap.php";
function getProd($category) {
if ($category == "books") {
return join(",", array(
"The WordPress Anthology",
"PHP Master: Write Cutting Edge Code",
"Build Your Own Website the Right Way"));
}
else {
return "No products listed under that category";
}
}
$server = new soap_server();
$server->register("getProd");
$server->service($HTTP_RAW_POST_DATA);
?>
and the client:
<?php
require_once "nusoap.php";
$client = new nusoap_client("http://localhost/nusoap/productlist.php");
$error = $client->getError();
if ($error) {
echo "<h2>Constructor error</h2><pre>" . $error . "</pre>";
}
$result = $client->call("getProd", array("category" => "books"));
if ($client->fault) {
echo "<h2>Fault</h2><pre>";
print_r($result);
echo "</pre>";
}
else {
$error = $client->getError();
if ($error) {
echo "<h2>Error</h2><pre>" . $error . "</pre>";
}
else {
echo "<h2>Books</h2><pre>";
echo $result;
echo "</pre>";
}
}
?>