dongqijuan3786 2018-10-24 11:07
浏览 307

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

I'm trying to pass the Header and Body to a SOAP Request. Due to the wrong practice, I'm getting the Connection error. When I tried the same using SOAP UI, Im getting the Proper response.

<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>

The below is my code:

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

?>

The error message is

Could not connect to host

But as said above, the same xml request is giving proper response through Soap UI application. What could be the issue here? I doubt on the Header assignment, Is that so, or somewhere else?

  • 写回答

1条回答 默认 最新

  • dongqiang4819 2019-03-12 02:22
    关注

    Try adding these to your client when you instantiate it. I've had it in the past where it caches from the wsdl and doesn't always connect, but this helps that. The trace and exceptions aren't essential but help IMO.

    array('trace' => 1, 'cache_wsdl'=>WSDL_CACHE_NONE, 'exceptions' => true)

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算