2011-05-06 134 views
0

我尝试更改名称空间,因为它需要与它尝试调用的.NET Web服务名称空间相匹配,但无法进行调用。我如何更改名称空间?PHP更改SOAP名称空间

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); 
    } 
} 

回答

0

如果您的SOAP消息中实际使用的命名空间,你可以使用SoapVar()指定特定变量的名称空间。当SoapClient构建消息时,它应该包含名称空间。