我的完整肥皂结构如下:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:uw="http://xmlns.oracle.com/Enterprise/HCM/services/UW_STBIO_REQ.V1">
<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<wsse:Security soap:mustUnderstand="1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<wsse:Username>XXXXXXXX</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">XXXXXXXX</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<uw:UW_STBIO_REQ>
<uw:EMPLID>428864</uw:EMPLID>
</uw:UW_STBIO_REQ>
</soapenv:Body>
</soapenv:Envelope>
我的PHP代码是:
<?php
$studentFeesInformationObj = new soapclient("wsdl/QAGetStudentBioInformation.wsdl", array('trace' => 1));
$security = array( 'UsernameToken' => array(
'Username'=>'XXXXXXXX',
'Password'=>'XXXXXXXX'
)
);
$header = new SoapHeader('wsse','Security',$security, false);
$studentFeesInformationObj->__setSoapHeaders($header);
$params = array('EMPLID' => '428864');
try{
$result = $studentFeesInformationObj->__soapCall('UW_STUDBIO_SO', array('parameters' => $params));
}
catch(Exception $e)
{
echo "<pre>$e<br>";
echo "REQUEST HEADERS:\n" . $studentFeesInformationObj->__getLastRequestHeaders() . "\n";
print_r($studentFeesInformationObj);
}
echo "<pre>";print_r($result);
?>
现在,当我尝试使用任何其他客户端(例如我的Chrome插件)时,它的工作正常但是当我尝试使用PHP时,它不起作用,我得到了以下响应:
SoapFault exception: [soapenv:Server] BEA-380001: Internal Server Error in /var/www/html/nusoap-0.9.5/client.php:20
答案 0 :(得分:0)
最后找到答案here:
class WsseAuthHeader extends SoapHeader {
private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
private $wsu_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd';
function __construct($user, $pass) {
$created = gmdate('Y-m-d\TH:i:s\Z');
$nonce = mt_rand();
$passdigest = base64_encode( pack('H*', sha1( pack('H*', $nonce) . pack('a*',$created). pack('a*',$pass))));
$auth = new stdClass();
$auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$auth->Nonce = new SoapVar($passdigest, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
$auth->Created = new SoapVar($created, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wsu_ns);
$username_token = new stdClass();
$username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);
$security_sv = new SoapVar(
new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),
SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
parent::__construct($this->wss_ns, 'Security', $security_sv, true);
}
}
并像这样创建标题:
$client->__setSoapHeaders(Array(new WsseAuthHeader("user", "pass")));