php - Passing Authentication Credentials in SoapHeader class -


i have xml file in format below

<?php  $xmlstr = <<<xml <?xml version="1.0" encoding="utf-8" ?> <soap:envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:tusa="http://schemas.datacontract.org/2004/07/tusa.services.consumerconnect" xmlns:tem="http://tempuri.org/"> <soap:header>     <authenticationcredentials>     <tusa:password>xxxxx</tusa:password>     <tusa:username>xxxxx</tusa:username>     </authenticationcredentials> </soap:header> <soap:body>     <tem:addproduct>         <tem:customerdetail>                 <tusa:addressline1>52 test drive</tusa:addressline1>                 <tusa:city>johannesburg</tusa:city>                 <tusa:maritalstatus>unknown</tusa:maritalstatus>                 //more nodes         </tem:customerdetail>     </tem:addproduct> </soap:body> </soap:envelope> xml; 

given following soap header

<soap:header>     <authenticationcredentials>     <tusa:password>xxxxx</tusa:password>     <tusa:username>xxxxx</tusa:username>     </authenticationcredentials> </soap:header> 

how can pass username , password soapheader class. have tried using code below getting error

authentication credentials required

try {     $auth = array(         'username'=>'xxxxx',         'password'=>'xxxxx',     );      $client = new \soapclient('https://test.com//indirect.svc?wsdl', array('soap_version' => soap_1_2, 'trace' => 1));      $actionheader = new \soapheader('http://www.w3.org/2005/08/addressing', action', http://tempuri.org/iindirect/addproduct');      $client->__setsoapheaders($actionheader);      $response = $client->addproduct($xmlstr); }  catch (\exception $e) {     echo "error!";     echo $e -> getmessage ();     echo 'last response: '. $client->__getlastresponse(); } 

i think you're looking this

$auth = [     'username' => 'xxxxx',     'password' => 'xxxxx', ];  $ns = 'http://www.w3.org/2003/05/soap-envelope/';  $header = new soapheader($ns, 'authenticationcredentials', $auth);          $client->__setsoapheaders($header); 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -