1. Go to this page and download the library: Download webair-srl/phpwsdl2 library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
webair-srl / phpwsdl2 example snippets
class MyWebService
{
/**
* Add two numbers
*
* @param int $a First number
* @param int $b Second number
* @return int Sum of the numbers
*/
public function add(int $a, int $b): int
{
return $a + $b;
}
/**
* Get user information
*
* @param string $username Username to lookup
* @return string JSON encoded user data
*/
public function getUser(string $username): string
{
return json_encode([
'username' => $username,
'email' => $username . '@example.com',
'created' => date('Y-m-d H:i:s')
]);
}
}
// service.php
2;
// Create and configure the service
$service = PhpWSDL2::create(
MyWebService::class,
'https://example.com/service.php',
'MyWebService'
);
// Handle all incoming requests
$service->handleRequest();
use PhpWSDL2\PhpWSDL2;
$service = new PhpWSDL2(MyWebService::class, 'https://example.com/service.php');
// Configure SOAP options
$service->getServer()->setSoapOptions([
'cache_wsdl' => WSDL_CACHE_MEMORY,
'soap_version' => SOAP_1_2
]);
$service->handleRequest();
use PhpWSDL2\PhpWSDL2;
$service = new PhpWSDL2(MyWebService::class, 'https://example.com/service.php');
// Generate service descriptor HTML
$html = $service->getServiceDescriptor();
// Generate WSDL
$wsdl = $service->generateWsdl();
// Get service methods
$methods = $service->getServiceMethods();
// Generate specific client
$soapClient = $service->getClientGenerator()->generate('soap', 'php');
bash
# POST request with JSON data
curl -X POST "https://example.com/service.php" \
-d "json={\"call\":\"add\",\"param\":[5,3]}"
# Returns JSON response
{"result": 8}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.