PHP code example of alpari / soap-client

1. Go to this page and download the library: Download alpari/soap-client 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/ */

    

alpari / soap-client example snippets


use Alpari\Components\SoapClient\Client\SoapClient;

$client = new SoapClient('http://example.com/service?wsdl');

$result = $client->targetServiceMethod(1, 2);

use Alpari\Components\SoapClient\Client\SoapClient;

$client = new SoapClient('http://example.com/service?wsdl');
$responses = $client->async(function (SoapClient $client) {
    $client->methodA(25);
    $client->methodB(64);
});

$client = new SoapClient('http://example.com/service?wsdl');

$client->setTimeout(60000); // in milli-seconds

$result = $client->targetServiceMethod(1, 2);

$client = new SoapClient('http://example.com/service?wsdl');

$client->setHeader('X-Header-Name', 'A value');

$result = $client->targetServiceMethod(1, 2);

use Psr\Log\NullLogger;

$client = new SoapClient('http://example.com/service?wsdl');

$client->setLogger(new NullLogger());

$result = $client->targetServiceMethod(1, 2);

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Alpari\Components\SoapClient\Test\TestSoapClient;

class SoapServiceTest extends WebTestCase
{
    public function testSoapServiceMethod()
    {
        $httpClient = static::createClient();
        $soapClient = new TestSoapClient($soapClient, 'wsdl url');

        $result = $soapClient->SoapServiceMethod('Method args');
        
        self::assertEquals(200, $httpClient->getResponse()->getStatusCode());
        self::assertEquals('something', $result);
    }
}

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Alpari\Components\SoapClient\Test\TestSoapClient;
use Symfony\Component\HttpKernel\Client;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpFoundation\Response;

class SoapServiceTest extends TestCase
{
    public function testSoapServiceMethod()
    {
        $httpClient = new Client(new class implements HttpKernelInterface {
            public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
            {
                return new Response(
                  // rendered content from application front controller 
                );
            }
        });
        $soapClient = new TestSoapClient($soapClient, 'wsdl url');

        $result = $soapClient->SoapServiceMethod('Method args');
        
        self::assertEquals(200, $httpClient->getResponse()->getStatusCode());
        self::assertEquals('something', $result);
    }
}