在PHP中发送SOAP auth Headers的问题

时间:2010-11-30 11:50:01

标签: php authentication soap

我对SOAP很新(即没有线索!)

客户端要求我与现有的SOAP服务进行交互,该服务需要通过我的SOAP头进行身份验证(一个简单的用户名和密码)

我可以使用3种方法,

的IsAlive IsAliveSecure ChangeUserDetails

IsAlive只返回true,我可以称之为没问题

IsAliveSecure通过适当的授权返回true,我无法让它返回true。

基本上我需要发送以下请求:

POST /ripplecomprovisioning.asmx HTTP/1.1
Host: provisioning.example.ie
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.blueface.ie/provisioning/IsAliveSecure"

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <SoapAuthHeader xmlns="http://www.example.ie/provisioning/">
      <Username>myusername</Username>
      <Password>mypassword</Password>
    </SoapAuthHeader>
  </soap:Header>
  <soap:Body>
    <IsAliveSecure xmlns="http://www.example.ie/provisioning/" />
  </soap:Body>
</soap:Envelope>

我的问题是如何在php中发送如上所述格式的请求?

这是我尝试的但没有成功:

$ soapClient = new SoapClient(“https://provisioning.example.ie/ripplecomprovisioning.asmx?WSDL”);

// Prepare SoapHeader parameters 
$sh_param = array( 
            'Username'    =>    'myusername', 
            'Password'    =>    'mypassword'); 
$headers = new SoapHeader('ripplecomprovisioning', 'SoapAuthHeaders', $sh_param); 

// Prepare Soap Client 
$soapClient->__setSoapHeaders(array($headers)); 
     $result = $soapClient->isAlive();

echo var_dump($result);

echo "<br /><br />";

   $result = $soapClient->IsAliveSecure();

echo var_dump($result);

以上输出如下:

object(stdClass)#3 (1) {
  ["IsAliveResult"]=>
  bool(true)
}
<br /><br />
Fatal error: Uncaught SoapFault exception: [soap:Server] System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.UnauthorizedAccessException: Attempted to perform an unauthorized operation.
   at example.VoIP.Provisioning.RipplecomProvisioningServices.IsAliveSecure()
   --- End of inner exception stack trace --- in /var/www/ripplecomweb/authentication/soap.php:20
Stack trace:
#0 [internal function]: SoapClient->__call('IsAliveSecure', Array)
#1 /var/www/ripplecomweb/authentication/soap.php(20): SoapClient->IsAliveSecure()
#2 {main}
  thrown in /var/www/ripplecomweb/authentication/soap.php on line 20

对此的任何帮助将不胜感激。我不能失败!

由于

千电子伏

1 个答案:

答案 0 :(得分:1)

如果我们能够看到服务的WSDL,那将会容易得多。 但请尝试以下步骤:

1.检查WSDL中的isAliveSecure方法,看看是否必须向其传递内容。

2.看看你发送的请求是什么样的:

var_dump($soapClient->__getLastRequest());
var_dump($soapClient->__getLastRequestHeaders());

(请确保您使用选项$soapClient为这些方法实例化'trace' => TRUE,否则它们将无效 - &gt;请参阅PHP manual)。

3.尝试以您确定应通过命令行手动正确的形式发送请求,例如:

curl -v -k -d @/path/to/the/file/with/the/request/xml http://service_url