api - SOAP PHP request error


I'm using a 3rd party api to request balances. I'm getting numerous errors on different tries but I know I'm close. here's my code for the call...

try {   
$wsdl_url = 'https://www.domain.com/SOAP?wsdl';
$UserID = 'UserID';
$Pwd= 'Password';
$client = new SOAPClient($wsdl_url);
$headerbody = array( 

//Create Soap Header.        
$header = new SOAPHeader('wsse', 'Security', $headerbody);        

//set the Headers of Soap Client. 

$getBalance = $client->balanceInquiry($BalanceInquiryRequest);
} catch (SoapFault $fault) {
echo $fault->faultcode . "-" . $fault->faultstring;  
//echo "REQUEST:\n" . htmlentities($client->__getLastRequest()) . "\n";


the output of this is...


and here's the xml for the request...

<soapenv:Envelope xmlns:req="http://domain.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
      <wsse:Security soapenv:mustUnderstand="0" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
         <wsse:UsernameToken wsu:Id="UsernameToken-1">
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Password</wsse:Password>
            <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">5Ht+O9hKvAEXhNJZSTLg==</wsse:Nonce>



Ok guys, the issue was that the WSSE in my code is a standard that doesn't play nice with PHP SOAPClient. I did a bit of research and discovered that there's a few methods to make these two play together nicely. What I did was to first determine the name space, username and password...

$username = 'USERNAME';
$password = 'PASSWORD';

$strWSSENS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";

Next is to create two classes which process this info(found help online)...

class clsWSSEAuth {
  private $Username;
  private $Password; 
    function __construct($username, $password) {

class clsWSSEToken {
  private $UsernameToken;
    function __construct ($innerVal){
      $this->UsernameToken = $innerVal;

then call these few functions to set headers etc...

  $objWSSEAuth = new clsWSSEAuth($objSoapVarUser, $objSoapVarPass);
  $objSoapVarWSSEAuth = new SoapVar($objWSSEAuth, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS);
  $objWSSEToken = new clsWSSEToken($objSoapVarWSSEAuth);
  $objSoapVarWSSEToken = new SoapVar($objWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'UsernameToken', $strWSSENS);
  $objSoapVarHeaderVal=new SoapVar($objSoapVarWSSEToken, SOAP_ENC_OBJECT, NULL, $strWSSENS, 'Security', $strWSSENS);
  $objSoapVarWSSEHeader = new SoapHeader($strWSSENS, 'Security', $objSoapVarHeaderVal,true, 'http://abce.com');

Then the rest is business as usual... with the SOAPClient...

People are also looking for solutions to the problem: php - Receiving nameserver set by passing one NS


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.