dsstjqsr631426 2012-03-27 16:32
浏览 75
已采纳

SOAP PHP请求错误

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...

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

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

//set the Headers of Soap Client. 
$client->__setSoapHeaders($header); 
//$client->__getLastResponse();
$BalanceInquiryRequest->AccountNo="7777700020";
$BalanceInquiryRequest->RetailerId="0123";

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

?>

the output of this is...

env:Server-java.lang.NullPointerException

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

<soapenv:Envelope xmlns:req="http://domain.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header>
      <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:Username>Username</wsse:Username>
            <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>
            <wsu:Created>2012-03-27T15:31:01.792Z</wsu:Created>
         </wsse:UsernameToken>
      </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <req:BalanceInquiryRequest>
         <req:AccountNo>7777700020</req:AccountNo>
         <req:RetailerId>0123</req:RetailerId>
      </req:BalanceInquiryRequest>
   </soapenv:Body>
</soapenv:Envelope>
  • 写回答

1条回答 默认 最新

  • duanqun9618 2012-03-28 15:41
    关注

    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) {
          $this->Username=$username;
          $this->Password=$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...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?