PHP code example of crphp / webservice

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

    

crphp / webservice example snippets


use Crphp\Webservice\Soap;

//No lugar deste array pode ser passada uma string contendo o xml
$args = [
            'tag1_exemplo'   => 'valor1',
            'tag2_exemplo'   => 'valor2',
            'no_pai' => [
                'no_filho' => 'valor1',
            ]
];
 
$obj = new Soap;
if($erro = $obj->setRequest('endereco_do_wsdl')) {
    exit($erro);
}

// Retorna um array com a lista de serviços contida no WSDL
// $obj->getMethods();

// Se o retorno for null então significa que a consulta não foi realizada
if(!$erro = $obj->doRequest('nomeServico', $args)) {
    // Perfumaria
    echo '<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>';
    echo "<pre class='prettyprint' >" . $obj->formatXML($obj->getResponse()) . "</pre>";
    
    /**
     * Retorna uma string contendo o cabeçalho da resposta http do webservice. Deve vir depois de doRequest()
     *
     * @see http://php.net/manual/pt_BR/function.nl2br.php Documentação para a função nlb2br.
     */
    echo nl2br($obj->getHeader());
} else {
    echo $erro;
}