SOAP-ERROR:编码:对象没有'FinalBookingDate'属性

时间:2015-01-23 18:29:45

标签: php soap wsdl soapui soap-client

在开始之前,我知道,这个错误意味着我应该定义属性FinalBookingDate,但只是继续阅读,你就会理解我的观点。

网址为:http://bestbuyhotel1.cangooroo.net/ws/2013/ClientBackOffice_b.asmx?op=getBookingList 我首先使用SoapUi测试,并且我成功获得了我需要的列表: soapui

在php上,我只能得到这个回复:SOAP-ERROR: Encoding: object has no 'FinalBookingDate' property

来自php的SoapClient是:

$params = array('soap_version'   => SOAP_1_2, 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, 'encoding'=>'UTF-8', 'trace' => 1, 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS);
$client = new \SoapClient('http://bestbuyhotel1.cangooroo.net/ws/2013/ClientBackOffice_b.asmx?wsdl', $params);

然后,检索数据的代码:

    /*
    $query = array(
        'InitialServiceDate' => '2015-01-20',
        'InitialBookingDate' => '2015-01-20',
        'FinalBookingDate' => '2015-01-20',
        'FinalServiceDate' => '2015-01-20',
        'CreationUserId' => 1338,
        'CityId' => 4166,
        'ServiceTypes' => array('eServiceType' => 'HOTEL')
    );
     */
    $query = array(
        'InitialBookingDate' => '2015-01-20',
        'ServiceTypes' => array('eServiceType' => 'HOTEL')
    );
    $args = new \stdClass;
    $args->credential = new \stdClass;
    $args->credential->UserName = $conn['userPass']['usr'];
    $args->credential->Password = $conn['userPass']['pass'];
    $args->searchBookingCriteria = new \stdClass;
    $args->searchBookingCriteria->InitialBookingDate = '2015-01-20';
    $args->searchBookingCriteria->ServiceTypes = new \stdClass;
    $args->searchBookingCriteria->ServiceTypes->eServiceType = 'HOTEL';

    //$args = array('credential'=>$credentials, 'searchBookingCriteria' => $query);
    $data = $conn['client']->getBookingList($args);
    print_r($data);
    exit;

正如你所看到的,我尝试了两种方法将$ args发送到getBookingList,据我所知,两者都是有效的,然后两者(带数组或对象)返回相同的错误。在最初评论的代码中,您可以看到我尝试定义Web服务要求的所有属性,但在定义了所有属性后,我得到一个空结果。

我的问题是,我应该在SoapClient上定义一些额外的参数吗?为什么SoapUI可以成功实现?我在这里失踪了什么?

奖励:SoapUI全屏打印,默认请求包括可选参数https://www.evernote.com/shard/s14/sh/fb5ac276-8147-4e09-95bb-afa0be66d7a6/d273441c74186bf1e600b42ab3303899/deep/0/SoapUI-5.0.0.png

2 个答案:

答案 0 :(得分:3)

你能尝试这种更直接的方法吗?

   try { 
    $params = array('soap_version'   => SOAP_1_2, 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP, 'encoding'=>'UTF-8', 'trace' => 1, 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS);
        $client = new SoapClient('http://bestbuyhotel1.cangooroo.net/ws/2013/ClientBackOffice_b.asmx?wsdl',$params); 
    } catch (SoapFault $E) { 
        echo $E->faultstring;
    }
    if ($client) { 
    $req_params = array('credential' => 
                            array('userName' => 'XXXXXXX',
                                  'Password' => 'XXXXXXX'),
                        'searchBookingCriteria' =>
                            array('BookingNumber' => array('int' => 'XXXXXXXXX'),
                                  'ServiceTypes' => array('eServiceType' => 'HOTEL'),
                                  'PassengerName'=> 'XXXXXXXX',
                                  'InitialBookingDate'=> '2015-01-16',
                                  'FinalBookingDate'=> '2015-01-16',
                                  'InitialServiceDate' => '2015-01-18',
                                  'FinalServiceDate' => '2015-01-18',
                                  'BookingStatus'=> array('eStatus' => 'ACTIVATED'),
                                  'PaymentStatus'=> array('ePaymentStatus' => 'Payed'),
                                  'CreationUserId'=> 'XXX',
                                  'CityId'=> 'XXXX',
                                  'ExternalReference'=> '')
        );
    $response = $client->__soapCall('getBookingList',array($req_params));
    var_dump($response);
    }

答案 1 :(得分:1)

尝试(并添加)此方法:

$args->searchBookingCriteria->FinalBookingDate = '2015-01-22';
$args->searchBookingCriteria->InitialServiceDate = '2015-01-22';
$args->searchBookingCriteria->FinalServiceDate = '2015-01-22';
$args->searchBookingCriteria->CreationUserId = 'abc';
$args->searchBookingCriteria->CityId = 'abc';