gopibabus
12/9/2017 - 5:42 PM

Create Simple SOAP Service

Create Simple SOAP Service

<?php
require 'lib/nusoap.php';
require 'BookInformation.php';

$server = new nusoap_server();

$server->configureWSDL("BookPrice", "urn:BookPrice");
$server->register(
    "getPrice",//function name
    ["find" => "xsd:string"],//input data
    ["return" => "xsd:integer"] //output data
);

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA)? $HTTP_RAW_POST_DATA: '';
$server->service($HTTP_RAW_POST_DATA);
<?php
//This function will return book price, given book name
function getPrice($find){
    $result = '';
    //variable storing book prices
    $books = [
        "java"=>288,
        "c"=>786,
        "php"=>237
    ];
    foreach($books as $book => $price){
        if($book === $find){
            return $price;
            break;
        }
    }
    return $result;
}