How to add this header to SOAP?

Asked

Viewed 361 times

1

Hello,

I have to do a check in a Web Service where a valid CPF is sent and returns me a true or false according to the validation.

I can access the Web Service with the following code:

    // INICIANDO O OBJETO CLIENTE INFORMANDO O WSDL 
    $client = new SoapClient('https://www5.oab.org.br/Integracao/CNA.svc?wsdl', $options = array(
                                                                                'soap_version' => SOAP_1_2,
                                                                                'trace'=>1, 
                                                                                'exceptions'=> 0
                ));

    // NOME DA FUNÇÃO A SER EXECUTADA
    $function = 'AdvogadoRegular';

    // PARÂMETROS DA FUNÇÃO A SER EXECUTADA
    $arguments= array('AdvogadoRegular' => array( 'cpf'  => '99999999999' ));

    // URL DO WEB SERVICE
    $options = array('location' => 'https://www5.oab.org.br/Integracao/CNA.svc');
    echo 'Resposta: <pre>';
    print_r($result);   
    echo '</pre>';

However, to have access to the Web Service you need an authentication of the type Soap Header Authentication. Below follows the example of Envelope SOAP.

    <?xml version="1.0" encoding="UTF-8"?>
      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:int="https://www5.oab.org.br/integracao/">
        <soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
          <token xmlns="http://CFOAB.Integracao">CHAVE_DE_AUTENTICAÇÃO</token>
          <wsa:To>https://www5.oab.org.br/Integracao/CNA.svc</wsa:To>
        </soapenv:Header>
        <soapenv:Body>
        </soapenv:Body>
      </soapenv:Envelope>

So I try to add Header to my SOAP with the following code.

// ADICIONANDO O HEADER
$auth = array('token' => 'xxxxxxxx');
$header = new SoapHeader('http://CFOAB.Integracao','token',$auth,false);

$client->__setSoapHeaders($header);

Now my question is the following, as if sending the parameters correctly to the header also sending the parameters xmlns:wsa and wsa:To described in the SOAP envelope?

Help me with this. Thank you

No answers

Browser other questions tagged

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