Error consuming webservice wsdl with PHP

Asked

Viewed 996 times

1

I am the days with this problem, I need to consume a wsdl webservice with php.

Follows my code

$cliente = new SoapClient('http://ws.tntbrasil.com.br:81/tntws/CalculoFrete?wsdl');

$funcao = 'calculaFrete';
$parametros = array(
  'calculaFrete' =>
      array(
        'cepDestino'                        => '95045080',
        'vlMercadoria'                      => '300.85',
        'psReal'                            => '30.000',
        'cdDivisaoCliente'                  => '1',
        'cepOrigem'                         => '95032620',
        'login'                             => '[email protected]',
        'nrIdentifClienteDest'              => '00010010099',
        'nrIdentifClienteRem'               => '10668759000109',
        'nrInscricaoEstadualDestinatario'   => '',
        'nrInscricaoEstadualRemetente'      => '0290501580',
        'senha'                             => '',
        'tpFrete'                           => 'C',
        'tpPessoaDestinatario'              => 'F',
        'tpPessoaRemetente'                 => 'J',
        'tpServico'                         => 'RNC',
        'tpSituacaoTributariaDestinatario'  => 'CO',
        'tpSituacaoTributariaRemetente'     => 'ME'
    )
);
$resultado = $cliente->__soapCall($funcao, $parametros);

You’re making my mistake again

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://ws.tntbrasil.com.br:81/tntws/CalculoFrete?wsdl' : failed to load external entity "http://ws.tntbrasil.com.br:81/tntws/CalculoFrete?wsdl" in /home/eggecom/public_html/tnt/calculaFrete.php:19 Stack trace: #0 /home/eggecom/public_html/tnt/calculaFrete.php(19): SoapClient->SoapClient('http://ws.tntbr...', Array) #1 {main} thrown in /home/eggecom/public_html/tnt/calculaFrete.php on line 19

I have tried in many ways and contacted the webservice provider where he did not give me the desired support but assured me about the variables being right.

PHP Version 5.6 inserir a descrição da imagem aqui

  • from your PHP server, you can access this URL http://ws.tntbrasil.com.br:81/tntws/Calculofrete? wsdl ?

  • Yeah, no problem at all.

  • If you run this code --> echo ("<pre>" . htmlentities(file_get_contents('http://ws.tntbrasil.com.br:81/tntws/CalculoFrete?wsdl')) . "</pre>"); the contents of WSDL appears?

  • Yes, I tested now and returned: <? xml version='1.0' encoding='UTF-8'? > <Definitions xmlns:tns="http://service.calculoFrete.mercurio.com" targetNamespace="http://service.calculoFrete.mercurio.com" name="Calculofrete"> <types> <xsd:schema> <xsd:import namespace="http://e.calculoFrete.mercouri.com" schemaLocation="http://ws.tntbrasil.com.br:81/tntws/CalculoFrete? xsd=1"/> </xsd:schema> [...]

  • Just in case, try adding the following line before $client = new Soap.... libxml_disable_entity_loader(false);. What happens now?

  • Nothing, same mistake :/

  • One last suggestion: remove the libxml_dis... I mentioned before and leave the $client like this: $cliente = new SoapClient('http://ws.tntbrasil.com.br:81/tntws/CalculoFrete?wsdl', array('cache_wsdl' => WSDL_CACHE_NONE));. Anyway, you’re looking like something with your server anyway. If the suggestion doesn’t work, start looking at your firewall if you’re allowing traffic on port 81, or something like.

  • Continue: Fatal error: Uncaught Soapfault Exception: [ns0:Server] java.lang.Nullpointerexception Thank you so far!

  • I solved the question: Within $parametros the array should be called in0 and not calculatFrete.

Show 4 more comments

1 answer

-1

If it helps...I managed to consume implementing the following 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;

Browser other questions tagged

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