Error in query to webservice CADSUS in PHP

0

Hello, everyone.

I'm trying to consume the "pesquisar" function of the CADSUS bus, but I get the error as a response

"Forced circuit exception";

The code used below is using Laravel 5.6 and PHP 7.1 :

Route::get('/ws/teste', function () {
    try {
        $opts = array(
            'http' => array(
                'user_agent' => 'PHPSoapClient'
            )
        );
        $context = stream_context_create($opts);
        $wsdlUrl = 'https://servicoshm.saude.gov.br/cadsus/CadsusService/v5r0?wsdl';
        $soapClientOptions = array(
            'trace' => 1,
            'stream_context' => $context,
            'cache_wsdl' => WSDL_CACHE_NONE,
            'Username' => 'CADSUS.CNS.PDQ.PUBLICO',
            'Password' => 'kUXNmiiii#RDdlOELdoe00966'
        );
        $client = new SoapClient($wsdlUrl, $soapClientOptions);
        $parameters = array(
            'CNESUsuario' => array(
                'CNES' => '6963447',
                'Usuario' => 'LEONARDO',
                'Senha' => ''
            ),
            'FiltroPesquisa' => array(
                'nomeCompleto' => 'SERGIO ARAUJO CORREIA LIMA',
                'tipoPesquisa' => 'IDENTICA'
            ),
            'higienizar' => 0
        );
        $result = $client->pesquisar($parameters);
        print_r($result);
    }
    catch(\Exception $e) {
        echo $e->getMessage();
    } });

If anyone knows what might be happening, please help me!

    
asked by anonymous 31.07.2018 / 16:11

2 answers

0

Good evening, I had a similar problem and had to change its code a lot, - the only way I could authenticate was by sending in the header with the namespaces defined in the example

<?php
try {
    $wsdlUrl = 'https://servicoshm.saude.gov.br/cadsus/CadsusService/v5r0?wsdl';
    $wsUser = 'CADSUS.CNS.PDQ.PUBLICO';
    $passWs = 'kUXNmiiii#RDdlOELdoe00966';
    $soapClientOptions = array(
	'trace' => 1,
	'cache_wsdl' => WSDL_CACHE_NONE
    );
    $client = new SoapClient($wsdlUrl, $soapClientOptions);
    $xmlheader = '
<wsse:Security SOAP-ENV:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <wsse:UsernameToken wsu:Id="UsernameToken-F6C95C679D248B6E3F143032021465917">
        <wsse:Username>' . $wsUser . '</wsse:Username>
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">' . $passWs . '</wsse:Password>
    </wsse:UsernameToken>
</wsse:Security>
';
    $header = new SoapHeader('http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd', 'Security', new \SoapVar($xmlheader, XSD_ANYXML), false);
    $client->__setSoapHeaders($header);

    $requestPesquisar = new stdClass();
    $requestPesquisar->CNESUsuario = new stdClass();
    $requestPesquisar->CNESUsuario->CNES = '6963447';
    $requestPesquisar->CNESUsuario->Usuario = 'LEONARDO';
    $requestPesquisar->CNESUsuario->Senha = '?';
    $requestPesquisar->FiltroPesquisa = new stdClass();
    $requestPesquisar->FiltroPesquisa->nomeCompleto = new stdClass();
    $requestPesquisar->FiltroPesquisa->nomeCompleto->Nome = 'SERGIO ARAUJO CORREIA LIMA';
    $requestPesquisar->FiltroPesquisa->tipoPesquisa = 'IDENTICA';
    $requestPesquisar->higienizar = '0';
    $result = $client->pesquisar($requestPesquisar);
    if ($result) {
	echo '<pre>', print_r($result), '</pre>';
    } else {
	echo '<h2>Request:</h2>';
	echo '<pre>', print_r($client->__getLastRequest()), '</pre>';
	echo '<h2>Header:</h2>';
	echo '<pre>', print_r($client->__getLastRequestHeaders()), '</pre>';
	echo '<h2>Response:</h2>';
	echo '<pre>', print_r($client->__getLastResponse()), '</pre>';
    }
} catch (Exception $e) {
    echo '<pre>', print_r($e), '<pre>';
}
?>

CNS Search (Single that returns complete data) Example XML

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:cad="http://servicos.saude.gov.br/cadsus/v5r0/cadsusservice" xmlns:cnes="http://servicos.saude.gov.br/wsdl/mensageria/v5r0/cnesusuario" xmlns:cns="http://servicos.saude.gov.br/schema/cadsus/v5r0/cns">
   <soap:Header>
	  <wsse:Security soap:mustUnderstand="1" 
	  xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" 
	  xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
	  <wsse:UsernameToken wsu:Id="UsernameToken-F6C95C679D248B6E3F143032021465917">
	  <wsse:Username>CADSUS.CNS.PDQ.PUBLICO</wsse:Username>
	  <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">kUXNmiiii#RDdlOELdoe00966</wsse:Password>
	  </wsse:UsernameToken>
	  </wsse:Security>
   </soap:Header>
   <soap:Body>
      <cad:requestConsultar>
         <cnes:CNESUsuario>
            <cnes:CNES>?</cnes:CNES>
            <cnes:Usuario>?</cnes:Usuario>
            <!--Optional:-->
            <cnes:Senha>?</cnes:Senha>
         </cnes:CNESUsuario>
         <cns:CNS>
            <cns:numeroCNS>AQUI_NUMERO_CNS</cns:numeroCNS>
         </cns:CNS>
      </cad:requestConsultar>
   </soap:Body>
</soap:Envelope>
    
02.08.2018 / 06:02
0

Good evening everyone! Do your requests return all of them?

    
08.08.2018 / 04:51