[英]PHP Change SOAP NameSpace
I am attempting to change the namespace as it needs to match the .NET web service namespace it is attempting to call however am unable to. 我正在尝试更改名称空间,因为它需要与它试图调用的.NET Web服务名称空间匹配,但是无法。 How do I change the name space?
如何更改名称空间?
class MSWCF extends SoapClient
{
function __doRequest($request, $location, $action, $version, $one_way = 0)
{
/*
* $request is a XML string representation of the SOAP request
* that can e.g. be loaded into a DomDocument to make it modifiable.
*/
$domRequest = new DOMDocument();
$domRequest->loadXML($request);
// modify XML using the DOM API, e.g. get the <s:Header>-tag
// and add your custom headers
$xp = new DOMXPath($domRequest);
$xp->registerNamespace('SOAP-ENV', 'http://schemas.xmlsoap.org/soap/envelope/');
// fails if no <s:Header> is found - error checking needed
$envelope = $xp->query('/SOAP-ENV:Envelope')->item(0);
// now add your custom header
$header = $domRequest->createElement('SOAP-ENV:header');
$security = $domRequest->createElement('o:Security');
$usernameToken = $domRequest->createElement('o:UsernameToken');
$usernameTokenuid = new DOMAttr('u:Id','uuid-4d9bf7e6-da00-4f72-8383-6037f12a0fb5-5');
$username = $domRequest->createElement('o:Username','');
$password = $domRequest->createElement('o:Password','');
$passwordtype = new DOMAttr('Type','http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText');
$password->appendChild($passwordtype);
$usernameToken->appendChild($username);
$usernameToken->appendChild($password);
$usernameToken->appendChild($usernameTokenuid);
$timestamp = $domRequest->createElement('u:TimeStamp');
$timestampuid = new DOMAttr('u:Id','_0');
$interval = new DateInterval("PT5M");
$dateCreated = new DateTime();
$dateExpires = new DateTime();
$dateExpires->add($interval);
$created = $domRequest->createElement('u:Created', $dateCreated->format(DATE_ISO8601));
$expires = $domRequest->createElement('u:Expires', $dateExpires->format(DATE_ISO8601));
$timestamp->appendChild($timestampuid);
$timestamp->appendChild($created);
$timestamp->appendChild($expires);
$security->appendChild($timestamp);
$security->appendChild($usernameToken);
$securitymust = new DOMAttr('SOAP-ENV:mustUnderstand','1');
$securityxml= new DOMAttr('xmlns:o','http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd');
$security->appendChild($securitymust);
$security->appendChild($securityxml);
$header->appendChild($security);
$envelope->appendChild($header);
$request = $domRequest->saveXML();
echo $request;
return parent::__doRequest($request, $location, $action, $version, $one_way = 0);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.