2012-10-17 23 views
1

我尝试使用下面的URL中提到的示例。但弄糊涂了他们是如何在这里构建$ wrapper的。任何人都可以告诉我如何创建包装以及它应该包含什么。 http://www.sis.utoronto.ca/web_services/code_samples.html我可以得到代码示例使用php和wsse

有人可以帮助我,因为我第一次使用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中定义的报头?;

请让我知道我在这里做什么错。

+0

您能否显示您拥有的代码并指出确切的问题? –

回答

0

我已经在我的Moodle模块中使用PasswordDigest实现了UserNameToken,该模块集成了Skillsofts OLSA Web Services。

看看: http://code.google.com/p/moodle2-skillsoft-activity/source/browse/trunk/skillsoft/olsalib.php#40

这是我创建围绕PHP SoapClient的包装,以支持发送的UserNameToken与密码摘要,你可以调整这个做简单的密码等等等等

它有一些Moodle特定的代码,用于获取诸如代理等等的东西,以及在文件系统上“缓存”WSDL的位置(使其更快地设置客户端 - 而不是每次将其设置为拉低WSDL等)

然后看看: http://code.google.com/p/moodle2-skillsoft-activity/source/browse/trunk/skillsoft/olsalib.php#483

我打电话给其中一个Web服务,您可以看到客户端是如何设置的以及如何传递用户名/密码。

相关问题