PHP 身份验证问题的 SOAP Header

PHP SOAP Header for Authentication Issue

我有以下 SOAP XML,我正在尝试使用 soap header 身份验证访问车辆详细信息。我试过下面的代码。我想,我在这方面遗漏了一些东西。你能帮忙吗

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 代码以及 SOAP Header,我创建如下。

<?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);

?>

如果我这里写错了,你能指导一下吗?

您可以像这样使用 __soapCall 方法:

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

在您的情况下,将像这样调用 soap 操作:

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

Read more