ron
ron

Reputation: 281

Access credential information from soap header in PHP

I need to access user name and password from the soap header inside php script. I can access the body information but could not access the header information. Here is the SOAp...

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"        xmlns:sec="http://schemas.xmlsoap.org/ws/2002/04/secext" 
xmlns:met="http://www.example.com/data">
   <soapenv:Header>
      <sec:Security>
         <UsernameToken>
            <Username>ron</Username>            
            <Password>pass</Password>
         </UsernameToken>
      </sec:Security>
   </soapenv:Header>
   <soapenv:Body>
      <met:columnInfo>
         <databaseName>MySQL</adaptorName>        
         <tableName>product</tableName>
      </met:columnInfo>
   </soapenv:Body>
</soapenv:Envelope>

Any help will be really appreciated.

Upvotes: 1

Views: 80

Answers (1)

ron
ron

Reputation: 281

Ok found the solution for that.

$server = new SoapServer($anywsdl);
$server->addFunction(addAllFuntions);
$server->handle();

Then in the same php script,

function Security($data){   
$UserToken=get_object_vars($data);
foreach($UserToken as $uToken){
    $credentialArray=get_object_vars($uToken);
    echo $credentialArray['Username'];
    echo $credentialArray['Password'];      
}

}

You would need $server->setClass($yourClass), if the Security() function was in different class.

Upvotes: 3

Related Questions