Error while performing a SOAP request

Asked

Viewed 438 times

-1

Hello, good afternoon!

I’m trying to perform a SOAP request with the TNT webservice, but I’m getting a bug and I don’t know what to do.

Just follow my code:

$cliente = new SoapClient('http://ws.tntbrasil.com.br:81/tntws/CalculoFrete?wsdl');
$funcao = 'calculaFrete';
$parametros = array('calculaFrete' => array('in0' => array(
            'cdDivisaoCliente'                 => 7,
            'cepDestino'                       => '36213000',
            'cepOrigem'                        => '36213000',
            'login'                            => '[email protected]',
            'nrIdentifClienteDest'             => '00000000000',
            'nrIdentifClienteRem'              => '28672407000190',
            'nrInscricaoEstadualDestinatario'  => '0000000000000',
            'nrInscricaoEstadualRemetente'     => '0086585810022',
            'psReal'                           => 15,
            'senha'                            => '',
            'tpFrete'                          => 'C',
            'tpPessoaDestinatario'             => 'F',
            'tpPessoaRemetente'                => 'J',
            'tpServico'                        => 'RNC',
            'tpSituacaoTributariaDestinatario' => 'CO',
            'tpSituacaoTributariaRemetente'    => 'CO',
            'vlMercadoria'                     => 650.17,
        )));
$resultado = null;      
$resultado = $cliente->__soapCall($funcao, $parametros);

You’re making the following mistake

Fatal error: Uncaught SoapFault exception: [ns0:Server] java.lang.NullPointerException in C:\xampp\htdocs\tnt\index.php:27 Stack trace: #0 C:\xampp\htdocs\tnt\index.php(27): SoapClient->__soapCall('calculaFrete', Array) #1 {main} thrown in C:\xampp\htdocs\tnt\index.php on line 27

It is noteworthy that this code worked since 2018, but in recent weeks began to give this error, someone would know to inform what I am doing wrong??

From now on I thank you all for your help.

1 answer

-1


If it helps, I just managed to consume TNT’s Ws by implementing this code:

$xmlr = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.calculoFrete.mercurio.com" xmlns:mod="http://model.vendas.lms.mercurio.com">
               <soapenv:Header/>
               <soapenv:Body>
                  <ser:calculaFrete>
                     <ser:in0>
                        <mod:login>' . $user_login . '</mod:login>
                        <mod:senha></mod:senha>
                        <mod:nrIdentifClienteRem>' . $cnpj . '</mod:nrIdentifClienteRem>
                        <mod:nrIdentifClienteDest>' . $idclientedest . '</mod:nrIdentifClienteDest>
                        <mod:tpFrete>' . $tipo_frete . '</mod:tpFrete>
                        <mod:tpServico>' . $tipo_servico . '</mod:tpServico>
                        <mod:cepOrigem>' . $cep_origem . '</mod:cepOrigem>
                        <mod:cepDestino>' . $cep_dst . '</mod:cepDestino>
                        <mod:vlMercadoria>' . number_format($valor_nf, 2, '.', '') . '</mod:vlMercadoria>
                        <mod:psReal>' . number_format($peso_total, 3, '.', '') . '</mod:psReal>
                        <mod:nrInscricaoEstadualRemetente>' . $ie . '</mod:nrInscricaoEstadualRemetente>
                        <mod:nrInscricaoEstadualDestinatario></mod:nrInscricaoEstadualDestinatario>
                        <mod:tpSituacaoTributariaRemetente>' . $situacao_trib . '</mod:tpSituacaoTributariaRemetente>
                        <mod:tpSituacaoTributariaDestinatario>CO</mod:tpSituacaoTributariaDestinatario>
                        <mod:cdDivisaoCliente>' . $divisao_cliente . '</mod:cdDivisaoCliente>
                        <mod:tpPessoaRemetente>' . $tipo_pessoa . '</mod:tpPessoaRemetente>
                        <mod:tpPessoaDestinatario>F</mod:tpPessoaDestinatario>
                     </ser:in0>
                  </ser:calculaFrete>
               </soapenv:Body>
            </soapenv:Envelope>';

// Chama o webservice                               
$location_URL = 'http://ws.tntbrasil.com.br/tntws/CalculoFrete?wsdl';
$uri = 'http://service.calculoFrete.mercurio.com';
$action_URL = 'http://ws.tntbrasil.com.br/tntws/CalculoFrete';

$client = new SoapClient(null, array(
        'location' => $location_URL,
        'uri'      => $uri,
        'trace'    => 1,
        ));

$xml = $client->__doRequest($xmlr, $location_URL, $action_URL, 1);

// Le o XML
$dom = new DOMDocument('1.0', 'ISO-8859-1');
$dom->loadXml($xml);

// Obtem os dados
$municipio = $dom->getElementsByTagName('nmMunicipioDestino')->item(0)->nodeValue;
$vltotal = $dom->getElementsByTagName('vlTotalFrete')->item(0)->nodeValue;
$prazo = $dom->getElementsByTagName('prazoEntrega')->item(0)->nodeValue;
  • Helped too much, with this code worked well, I was already losing my head after my code stopped working, thank you very much!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.