我尝试使用下面 url 中提到的示例。但对他们如何在这里构建 $wrapper 感到困惑。谁能告诉我如何创建包装器以及它应该包含什么。 http://www.sis.utoronto.ca/web_services/code_samples.html。
有人可以在这里帮助我,因为我是第一次使用 wsse,所以不知道如何使用它。我正在从 PHP 到 .net wsse 进行肥皂调用。
请让我知道如何在此示例中传递标头。
<?php
class WSSESoapClient extends SoapClient {
protected $wsseUser;
protected $wssePassword;
public function setWSSECredentials($user, $password) {
$this->wsseUser = $user;
$this->wssePassword = $password;
}
public function __doRequest($request, $location, $action, $version, $one_way = 0) {
if (!$this->wsseUser or !$this->wssePassword) {
return parent::__doRequest($request, $location, $action, $version, $one_way = 0);
}
// get SOAP message into DOM
$dom = new DOMDocument();
$dom->loadXML($request);
$xp = new DOMXPath($dom);
$xp->registerNamespace('SOAP-ENV', 'http://schemas.xmlsoap.org/soap/envelope/');
// search for SOAP header, create one if not found
$header = $xp->query('/SOAP-ENV:Envelope/SOAP-ENV:Header')->item(0);
if (!$header) {
$header = $dom->createElementNS('http://schemas.xmlsoap.org/soap/envelope/', 'SOAP-ENV:Header');
$envelope = $xp->query('/SOAP-ENV:Envelope')->item(0);
$envelope->insertBefore($header, $xp->query('/SOAP-ENV:Envelope/SOAP-ENV:Body')->item(0));
}
// add WSSE header
$usernameToken = $dom->createElementNS('http://schemas.xmlsoap.org/ws/2002/07/secext', 'wsse:UsernameToken');
$username = $dom->createElementNS('http://schemas.xmlsoap.org/ws/2002/07/secext', 'wsse:Username', $this->wsseUser);
$password = $dom->createElementNS('http://schemas.xmlsoap.org/ws/2002/07/secext', 'wsse:Password', $this->wssePassword);
$usernameToken->appendChild($username);
$usernameToken->appendChild($password);
$header->appendChild($usernameToken);
// perform SOAP call
$request = $dom->saveXML();
return parent::__doRequest($request, $location, $action, $version, $one_way = 0);
}
} // class WSSESoapClient
$wsdl = 'Mywsdlurl';
$sClient = new WSSESoapClient ($wsdl,array( "trace" => 1 ));
$sClient->setWSSECredentials('username', 'password');
$wrapper->AccountName = new SoapVar("NEw User", XSD_STRING);
$wrapper->AccountInfo->propertyID = new SoapVar(2, XSD_STRING);
try {
$result = $sClient->CreateAccount($wrapper);
print_r($result);
} catch (SoapFault $fault) {
print("Fault string: " . $fault->faultstring . "\n");
print("Fault code: " . $fault->detail->WebServiceException->code . "\n");
}
echo $sClient->__getLastRequest();
// "<br>" .
// $sClient->__getLastResponse();
?>
当我检查 __getLastRequest 时,它没有附加 _doRequest 中定义的标头;
请让我知道我在这里做错了什么。