如何在PHP中传递SOAP标头和主体作为参数

时间:2018-10-24 11:07:01

标签: php soap wamp wampserver soap-client

我正在尝试将标头和正文传递给SOAP请求。由于错误的做法,我遇到了连接错误。当我使用SOAP UI尝试相同操作时,我得到了正确的响应。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:adp="http://abcddetails.com/">
   <soapenv:Header>
      <adp:UserIdentifierSoapHeaderIn>
         <!--Optional:-->
         <adp:UserName>USER1</adp:UserName>
         <!--Optional:-->
         <adp:Password>PASS</adp:Password>
      </adp:UserIdentifierSoapHeaderIn>
   </soapenv:Header>
   <soapenv:Body>
      <adp:getVehicleDetails>
         <!--Optional:-->
         <adp:request>
            <adp:SystemCode>101</adp:SystemCode>
            <!--Optional:-->
            <adp:UserID>101</adp:UserID>
            <!--Optional:-->
            <adp:PlateInfo>
               <adp:PlateNo>44444</adp:PlateNo>
               <adp:PlateOrgNo>1</adp:PlateOrgNo>
               <adp:PlateColorCode>48</adp:PlateColorCode>
               <adp:PlateKindCode>1</adp:PlateKindCode>
               <adp:PlateTypeCode>1</adp:PlateTypeCode>
               <adp:PlateSourceCode>3</adp:PlateSourceCode>
            </adp:PlateInfo>
            </adp:request>
      </adp:getVehicleDetails>
   </soapenv:Body>
</soapenv:Envelope>

以下是我的代码:

<?php 

echo "Hello world";
echo "ADDED the below two lines"
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);


$wsdl   = "https://abcddetails.com/getSoapDetails.asmx?WSDL";
$client = new SoapClient($wsdl, array('trace'=>1));  

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

echo "Header Passed... Body starts";

// web service input params
$request_param = array(
    'getCarDetails' => array(
        'request' => array(
            'SystemCode' => 101,
            'UserID' => 101),
        'PlateInfo' => array(
            'PlateNo' => 44444,
            'PlateOrgNo' => 1,
            'PlateColorCode' => 48,
            'PlateKindCode' => 1,
            'PlateTypeCode' => 1,
            'PlateSourceCode' => 3 )              
        )
    );

$responce_param = null;
try
{
    $responce_param = $client->__soapCall('getCarDetails', ['parameters' => $request_param]);
} 
catch (Exception $e) 
{ 
    echo "<h2>Exception Error!</h2>"; 
    echo $e->getMessage(); 
}

print_r($responce_param);

?>

错误消息是

  

无法连接到主机

但是如上所述,相同的xml请求通过Soap UI应用程序给出了正确的响应。这里可能是什么问题?我对标头分配感到怀疑,是这样还是其他地方?

0 个答案:

没有答案