-2

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.

Daniel Kennedy
  • 708
  • 11
  • 18
  • Possible duplicate of [php web service example](http://stackoverflow.com/questions/4242355/php-web-service-example) – Elber CM Dec 28 '16 at 14:08

1 Answers1

0

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>";
    }
}
?>
Daniel Kennedy
  • 708
  • 11
  • 18