代码之家  ›  专栏  ›  技术社区  ›  Kevin Bradshaw

在PHP中发送SOAP身份验证头时出现问题

  •  5
  • Kevin Bradshaw  · 技术社区  · 14 年前

    我对肥皂很陌生(也就是说,不知道!)

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

    我有三种方法可供选择,

    伊莎莉 IsLiveSecure安全 更改用户详细信息

    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 回复  |  直到 9 年前
        1
  •  1
  •   Christof    9 年前

    好吧,如果我们能看到服务的WSDL,那就容易多了。 但请尝试以下步骤:

    1.检查isalivesecure方法的WSDL,看看是否需要向它传递一些东西。

    2.查看您发送的请求的实际外观:

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

    (确保你正在实例化 $soapClient 有选择权 'trace' => TRUE 有关这些方法,或者它们不起作用,请参阅 PHP manual )

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

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