dtziv24262 2017-03-28 08:41
浏览 23
已采纳

肥皂体总是空白的

I am trying to integrate web services using soap.

This is the xml file:

http://uatapiout.islandhopper.in/Service1.svc?wsdl

And this is code which I am trying:

<?php

$wsdl = 'http://uatapiout.islandhopper.in/Service1.svc?wsdl';

$xml_array["RequestType"] = "AvailabilityRQ";
$xml_array["Login"] = array("UserName"=>"test","Password"=>"test","Version"=>"3.0");

$xml_array["CheckAvailabilityCriteria"] = array("CheckIn" => "07/05/2017","CheckOut"=> "07/11/2017","CountryID"=> "MAU","CityID" => "MAU","Currency" => "USD","Adult" => "2","Rooms"=>array("Room"=>array("Adult"=>"2","Child"=>"0")));

$trace = true;
$exceptions = true;

try
{

    $client = new SoapClient($wsdl, array('trace' => 1)); 

    $response = $client->HotelSearch($xml_array );

    print_r($client->__getLastRequest());
    print_r($client->__getLastResponse());

}

catch (Exception $e)
{
    echo "Error!";
    echo $e ->getMessage ();
    echo 'Last response: '. $client->__getLastResponse();
}

And $client->__getLastRequest() always gives me blank body:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://tempuri.org/"><SOAP-ENV:Body><ns1:HotelSearch/></SOAP-ENV:Body></SOAP-ENV:Envelope>

So, the question is that why this request has a blank body.

Please suggest me, what am I doing wrong?

Thanks in advance.

Edit:

This is sample xml request:

<XMLRequest>
<RequestType>AvailabilityRQ</RequestType>
<Login>
    <UserName>UserName</UserName>
    <Password>Password</Password>
    <Version>3.0</Version>
</Login>
<CheckAvailabilityCriteria>
    <CheckIn>07/05/2016</CheckIn>
    <CheckOut>07/11/2016</CheckOut>
    <CountryID>MAU</CountryID>
    <CityID>MAU</CityID>
    <Currency>USD</Currency>
    <HotelCode></HotelCode>
    <HotelName></HotelName>
    <ClientNationality></ClientNationality>
    <Rooms>
        <Room>
           <Adult>2</Adult>
           <Child>2</Child>
           <ChildAges>
                <ChildAge>7</ChildAge>
                <ChildAge>14</ChildAge>
           </ChildAges>
        </Room>
        <Room>
           <Adult>2</Adult>
           <Child>0</Child>
       </Room>
    </Rooms>
</CheckAvailabilityCriteria>
</XMLRequest>
  • 写回答

1条回答 默认 最新

  • douhuo3696 2017-04-05 07:51
    关注

    Thank you all for your support.

    Now, I am doing that using nusaop lib.

    This is the code:

    require_once('nusoap/lib/nusoap.php');
    $wsdl = 'wdls url';
    
    $xml_array["RequestType"] = "AvailabilityRQ";
    $xml_array["Login"] = array("UserName"=>"username","Password"=>"password","Version"=>"version");
    
    $xml_array["CheckAvailabilityCriteria"] = array("CheckIn" => "07/05/2017","CheckOut"=> "07/11/2017","CountryID"=> "MAU","CityID" => "MAU","Currency" => "USD","Rooms"=>array("Room"=>array("Adult"=>"2","Child"=>"0")));
    
    $xml_array1['XMLRequest'] =$xml_array;
    
    
    $client = new nusoap_client($wsdl, false);
    $client->soap_defencoding = 'UTF-8';
    
    $err = $client->getError();
    
    if ($err)
    {
        echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
        echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
        exit();
    }
    
    $result = $client->call('HotelSearch', $xml_array1,'','http://tempuri.org/IService1/HotelSearch',false,false,'','');
    
    if ($client->fault) 
    {
    
        echo '<h2>Fault (Expect - The request contains an invalid SOAP body)</h2>';
    }
    else 
    {
        $err = $client->getError();
    
        if ($err) 
        {
            echo '<h2>Error</h2><pre>' . $err . '</pre>';
        }
        else
        {
    
            $result_count = $array_result['TotalResult'];
    
            if($result_count)
            {
                $hotels_list = $array_result['AvailHotels']['Hotel'];
    
                for($i=0; $i<count($hotels_list);$i++)
                {
                    $hotel_name = $hotels_list[$i]['@attributes']['Name'];
                    $hotel_code = $hotels_list[$i]['@attributes']['Code'];
    
                    echo "Hotel name is <i>$hotel_name</i> and hotel code is <i>$hotel_code</i>";
    
                    echo "</br></br>";
                }
            }
    
        }
    }
    

    Hope, this will help someone :)

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

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题