用PHP来使用WSDL验证 [英] Authentication using PHP to consume wsdl
问题描述
我在PHP通过连接到WSDL服务的麻烦。麻烦似乎进来的身份验证。这里是我的code迄今:
I'm having trouble connecting to a wsdl service through PHP. The trouble seems to come in authentication. Here is my code so far:
$soapURL = "http://myurl?wsdl";
$soapLogin = Array(
'User ID'=>'myusername',
'Password'=>"mypassword"
);
$soapClient = new SoapClient($soapURL, $soapLogin);
$soapResult = $soapClient->mySoapFunction();
我的用户名和密码,客户端的定义,我可以看到WSDL生成XML文件,但如果我引用正确的用户名和密码,不,我不能辨别。当试图连接我收到以下错误:
I have the username and password as defined by the client, and I can see the XML file that the wsdl generates but no I cannot discern if I am referencing the username and passwords correctly. When trying to connect I get the following error:
Fatal error: Uncaught SoapFault exception: [a:InvalidSecurity] An error occurred when verifying security for the message. in E:\xampp\htdocs\TRMSosf\index.php:15 Stack trace: #0 E:\xampp\htdocs\TRMSosf\index.php(15): SoapClient->__call('GetWeekEvents', Array) #1 E:\xampp\htdocs\TRMSosf\index.php(15): SoapClient->GetWeekEvents('10', '20130527') #2 {main} thrown in E:\xampp\htdocs\TRMSosf\index.php on line 15
我是新来使用SOAP和相当新的PHP,任何帮助是AP preciated。
I'm new to using SOAP and fairly new to PHP, any help is appreciated.
推荐答案
我发现这里的另一篇文章的答案:<一href=\"http://stackoverflow.com/questions/12927822/can-i-get-$c$c-samples-working-with-php-and-wsse\">Can我得到code样品使用PHP和WSSE 工作
I found the answer in another article here: Can I get Code Samples working with php and wsse
这涉及处理该WSSE认证类
it involved a class that handled the WSSE authentication
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);
}
这篇关于用PHP来使用WSDL验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!