<?php
/*
 * PHP SOAP - How to create a SOAP Server and a SOAP Client
 */

function WSDL()
{
    // We need to buffer the output so that we can send a Content-Length header with the WSDL
    ob_start();
    $wsdl = file_get_contents('service.wsdl');
    $wsdl = str_replace('{{XMDS_LOCATION}}', "https://secure.vs.co.id/lokon/soap/server.php", $wsdl);
    echo $wsdl;

    // Get the contents of the buffer and work out its length
    $buffer = ob_get_contents();
    $length = strlen($buffer);

    // Output the headers
    header('Content-Type: text/xml; charset=ISO-8859-1\r\n');
    header('Content-Length: ' . $length);

    // Flush the buffer
    ob_end_flush();
    exit;
}
    
//a basic API class
class MyAPI
{
//  function Hello($msg) {
//      return "Hello " . $msg . " with WSDL";
//  }
  
  function Hello($hardwareKey)
    {
      return "Hello " . $hardwareKey . " with WSDL ";
    }
}

if (isset($_GET['wsdl']) || isset($_GET['WSDL']))
    WSDL();
    
//ini_set("soap.wsdl_cache_enabled", "0"); 

try {
  //create a new SOAP server
  $server = new SoapServer('https://secure.vs.co.id/lokon/soap/service.wsdl');
  //attach the API class to the SOAP Server
  $server->setClass('MyAPI');
  //$server->addFunction("Hello");
  //start the SOAP requests handler
  $server->handle();
}
catch (Exception $e)
{
    $serviceResponse->ErrorServerError('Unable to create SOAP Server');
}

?>
