Set PHP Soapclient custom parameters

Asked

Viewed 349 times

3

I am consuming an external webservice via PHP and the same requests authentication in a different way, the login and password has to be passed within XML. But I can’t authenticate.

The call for service is being created the way below.

public static function myFunction ($param){

        $soapClient = new \SoapClient('my_wsdl', [
            "trace"     => 1,
            "exception" => 0,
            'Login' => '*',
            'Senha' => '*'
        ]);

        return($soapClient->myService($param));
}

The service expects an XML as below:

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="meu_endereco_api">
   <soapenv:Header>
   <Autenticacao>   
        <Login>*****</Login>
        <Password>****</Senha>
   </Autenticacao>
   </soapenv:Header>
   <soapenv:Body>
      <api:minha_api soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
         <meu_parametro xsi:type="xsd:string">$param</meu_parametro>
      </api:minha_api>
   </soapenv:Body>
</soapenv:Envelope>

The service returns me authentication error:

object(stdClass)[783]
  public 'Parametro' => string 'ERRO NAO AUTENTICADO'

Does anyone have any idea how to send the authenticated request the parameters in this expected format?

No answers

Browser other questions tagged

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