Skip to content

Instantly share code, notes, and snippets.

@dwihujianto
Created December 24, 2015 15:11
Show Gist options
  • Save dwihujianto/b68c052a7626ba9766de to your computer and use it in GitHub Desktop.
Save dwihujianto/b68c052a7626ba9766de to your computer and use it in GitHub Desktop.
Create Soap (MyStyle)
<?php
/**
* @author Dwi Hujianto <[email protected]>
*/
require_once 'lib/nusoap.php';
class Resourceapi extends soap_server
{
/**
* set Direktori Api server
*/
protected $targetNameSpace = 'http://localhost/soap/';
/**
* set Method atu fungsi yang akan digunakan untuk interaksi Server
*/
protected $method = 'credible';
protected $rawPostData;
public function __construct()
{
$this->rawPostData = file_get_contents('php://input');
$this->create();
}
/**
* Methor credible serta behavior registerMethod
* Silahkan modifikasi sendiri sesuai kebutuhan
*/
public function credible($user=null,$pass=null)
{
$data = [
'user' => $user,
'pass' => $pass
];
return $data;
}
private function registerMethod()
{
$this->register
(
$this->method,
[
'user' => 'xsd:string',
'pass' => 'xsd:string'
],
[
'return' => 'xsd:Array'
],
$this->targetNameSpace
);
}
private function create()
{
$this->configureWSDL($this->method,$this->targetNameSpace);
$this->wsdl->schemaTargetNamespace = $this->targetNameSpace;
$this->registerMethod();
$this->service
(
isset($this->rawPostData)
? $this->rawPostData
: null
);
}
}
new Resourceapi();
<?php
require_once 'lib/nusoap.php';
$targetNameSpace = 'http://localhost/soap/';
$server = new soap_server();
$server->configureWSDL('credible',$targetNameSpace);
$server->wsdl->schemaTargetNamespace = $targetNameSpace;
$server->register(
'credible',
[
'username' => 'xsd:string',
'password' => 'xsd:string'
],
['return' => 'xsd:Array'], // Jika tunggal gunakan string saja
$targetNameSpace
);
function credible($username,$password)
{
$query = [
'username' => $username,
'password' => $password
];
return $query;
}
$rawPostData = file_get_contents("php://input");
$server->service(isset($rawPostData) ? $rawPostData : '');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment