dongzi0602 2018-10-16 07:18
浏览 188
已采纳

用于身份验证问题的PHP SOAP标头

I have the below SOAP XML, Im trying to access the vehicle details with the soap header authentication. I have tried the below code. I think, Im missing something on this. Can u help

SOAPAction: "http://abcddetails.org/getVehicleDetails"

<?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>
    <UserIdentifierSoapHeaderIn xmlns="http://abcddetails.org/">
      <UserName>string</UserName>
      <Password>string</Password>
    </UserIdentifierSoapHeaderIn>
  </soap:Header>
  <soap:Body>
    <getVehicleDetails xmlns="http://abcddetails.org/">
      <request>
        <SystemCode>int</SystemCode>
        <UserID>string</UserID>
        <PlateInfo>
          <PlateNo>long</PlateNo>
          <PlateOrgNo>long</PlateOrgNo>
          <PlateColorCode>int</PlateColorCode>
        </PlateInfo>
        <ChassisNo>string</ChassisNo>
      </request>
    </getVehicleDetails>
  </soap:Body>

PHP code along with the SOAP Header, I have created as the below.

<?php 
$wsdl   = "http://abcddetails.org/InspectionServices.asmx?WSDL";
$client = new SoapClient($wsdl, array('trace'=>1));  // The trace param will show you errors stack

 $auth = array(
        'Username'=>'XXXXX',
        'Password'=>'XXXXX',
    );
$header = new SOAPHeader($wsdl, 'UserIdentifierSoapHeaderIn', $auth);        
$client->__setSoapHeaders($header);

// web service input params
$request_param = array(
    "SystemCode" => 4,
    "UserID" => "TEST",
    "ChassisNo" => '1N4AL3A9XHC214925'

);
$responce_param = null;
try
{
    $responce_param = $client->getVehicleDetails($request_param);
   //$responce_param =  $client->call("webservice_methode_name", $request_param); // Alternative way to call soap method
} 
catch (Exception $e) 
{ 
    echo "<h2>Exception Error!</h2>"; 
    echo $e->getMessage(); 
}

print_r($responce_param);

?>

Can u guide if anything I have written wrong here in this.

  • 写回答

1条回答 默认 最新

  • doubaoxue5788 2018-10-16 07:28
    关注

    You can use the __soapCall method like this:

    $result = $client->__soapCall('webserviceMethodeName', ['parameters' => $params]);
    

    In your case a soap action would be invoked like this:

    $responce_param = $client->__soapCall('getVehicleDetails', ['parameters' => $request_param]);
    

    Read more

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧