2013-10-16 19 views
1

这里是怎么想的,我可以成功请求第一个,这个给我一个ID,我必须用这个ID作为第二个请求,但第二个如何?PHP SOAP,请问这个

try { 
    $clienteSOAP = new SoapClient ('someservicehere'); 
    $header = array('Username' => 'user', 'Password' => 'pass', 'DeviceType'=> 3,'Platform'=>'1'); 
    $response = $clienteSOAP->GetSession($header); 
    //echo $response->SessionID: 
    //15987451 
    $header2 = array('Username' => 'user', 'Password' => 'pass','SessionID' => '15987451' , 'DeviceType'=> 3,'Platform'=>'1'); 
    $clienteSOAP->GetBalance($header2); 
    //GetBalance throws error, 
} catch (SoapFault $e) { 
    var_dump ($e); 
} 

GetSession的xml,这个工程很棒!

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ext="someTextHere"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <ext:GetSessionRequest> 
      <ext:Username></ext:Username> 
      <ext:Password></ext:Password> 
      <ext:DeviceType></ext:DeviceType> 
      <!--Optional:--> 
      <ext:Platform></ext:Platform> 
     </ext:GetSessionRequest> 
    </soapenv:Body> 
</soapenv:Envelope> 

但是为什么呢?

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ext="SomeTextHereToo"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <ext:GetBalanceRequest> 
      <ext:AuthenticationData> 
      <!--Optional:--> 
      <ext:Username></ext:Username> 
      <!--Optional:--> 
      <ext:Password></ext:Password> 
      <!--Optional:--> 
      <ext:SessionID></ext:SessionID> 
      </ext:AuthenticationData> 
      <ext:DeviceType></ext:DeviceType> 
      <!--Optional:--> 
      <ext:Platform></ext:Platform> 
     </ext:GetBalanceRequest> 
    </soapenv:Body> 
</soapenv:Envelope> 

回答

1

你必须包装在一个单独的阵列的认证数据,在第二个定义有包装的认证证书的附加元件()。

这应该工作:

try { 
    $clienteSOAP = new SoapClient ('someservicehere'); 
    $header = array('Username' => 'user', 'Password' => 'pass', 'DeviceType'=> 3,'Platform'=>'1'); 
    $response = $clienteSOAP->GetSession($header); 
    $header2 = array('AuthenticationData' => array(
         'Username' => 'user', 
         'Password' => 'pass', 
         'SessionID' => '15987451' 
        ), 
        'DeviceType'=> 3, 
        'Platform'=>'1' 
       ); 
    $clienteSOAP->GetBalance($header2); 
} catch (SoapFault $e) { 
    var_dump ($e); 
} 

由于用户名,密码和会话ID都是可选的我想你可以用用户名和密码,或会话ID进行身份验证。所以你可能不需要在第二个电话中提供用户名和密码。

+0

谢谢你,你太棒了... – Crashman