1

I encounter some problems when I try to call a method of api with authentication.

 $auth = (object) array(
                'user'=>'username',
                'password'=>'password',
                'company'=> 'companyname'
          );
         
    $url = 'https://webservices.gocadservices.com/NVS?wsdl';
    
    $soap = new SoapClient('https://webservices.gocadservices.com/NVS?wsdl',$auth);
    echo $soap->nop();

I get an error : The user parameter is empty or missing.

My question : How can I send a request xml like this :

<?xml version='1.0' encoding='UTF-8'?> 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
<soapenv:Header> 
<xs:nvheader xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
<xs:nvcommand> 
    <xs:user>
          username
    </xs:user> 
    <xs:password>
         mot de passe
     </xs:password> 
     <xs:company>
          companyname
      </xs:company> 
</xs:nvcommand> 
</xs:nvheader> 
</soapenv:Header> 
</soapenv:Envelope> 

I must have this structure so that the API SOAP will work. Thanks.

1

1 Answer 1

1

You need to set a SOAP Header for this to work:

 $nvcommand = (object)[
'user' => 'username',
'password' => 'password',
'company' => 'company'];

$authHeader = new SoapHeader('namespace','nvcommand', $nvcommand);

$soapClient = new SoapClient('http://localhost:44333/SoapService.com?wsdl', $soapOptions);
$soapClient->__setSoapHeaders($authHeader);

$return = $soapClient->__soapCall('HelloWorld',[]);

This will send a SOAP Header

<env:Header>
    <ns2:nvcommand>
        <user>username</user>
        <password>password</password>
        <company>company</company>
    </ns2:nvcommand>
</env:Header>

along with the Request. The options array in the SoapClient ctor isnt used to pass auth information. Please refer to https://www.php.net/manual/de/soapclient.construct.php

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.