SOAP-ERROR: Encoding: object has no 'any' property

1

I am quite complicated doing a requirement to a webservice with PHP Soap. The requests in which I consult data work well, but there is one that makes a reservation in a hotel and throws me the error

SOAP-ERROR: Encoding: object has no 'any' property

The following code asks ws to bring the hotels dates a city, it works perfectly. In the documentation the different xml are shown.

$xml = '<Request Version="1.0" encoding="utf-8">
<d>2</d>
<a>AF-AVV</a>
<l>esp</l>
</Request>';

$funcion = "GetHotels";
ini_set('soap.wsdl_cache_enabled', 0);
$wsdl = 'http://testxml.e-tsw.com/AffiliateService/AffiliateService.svc?Wsdl';
$client = new SoapClient($wsdl);
$xml_busqueda = simplexml_load_string($xml, NULL, LIBXML_NOCDATA);
 try {
     $respuesta     = $client->__soapCall($funcion, array('Parameters' => $xml_busqueda));
     echo "RESPUESTA DEL WEB SERVICE";
     echo "<pre>";
     print_r($respuesta);
     echo "<pre>";
    } catch (SoapFault $exception) {
        echo $exception->getMessage();
    }

In the process that makes "Book" (book), it gives me the error SOAP-ERROR: Encoding: object has no 'any' property. The xml of the reservation is the one that appears in the documentation. It is quite long, but it basically contains the necessary data to make a reservation.

$xml = '<Request Type="Reservation" Version="1.0">
<affiliateid>AF-AVV</affiliateid>
<language>esp</language>
<currency>PE</currency>
<uid>m2r32b14es10socxtxs4y4ht</uid>
<ip>201.147.113.232</ip>
<firstname>prueba</firstname>
<lastname>prueba</lastname>
<emailaddress>[email protected]</emailaddress>
<country>MX</country>
<address>bonampak 4</address>
<city>cancun</city>
<state>QROO</state>
<zip>77500</zip>
<total>12346.51</total>
<naturalperson>
<gender></gender>
<nationality></nationality>
<number></number>
<type></type>
</naturalperson>
<legalperson>
<businessname></businessname>
<number></number>
<type></type>
</legalperson>
<phones>
<phone>
<type>2</type>
<number>9981454221</number>
</phone>
</phones>
<hotels>
<hotel>
<hotelid>100</hotelid>
<roomtype>SUPOV</roomtype>
<mealplan>EP</mealplan>
<datearrival>20141113</datearrival>
<datedeparture>20141115</datedeparture>
<couponid></couponid>
<marketid>INTER</marketid>
<contractid>2</contractid>
<dutypercent>0</dutypercent>
<rooms>
<room>
<amount>985.34</amount>
<status>AV</status>
<ratekey>90cba867-f916-4fb9-8cb4-ec925ded0fb3</ratekey>
<adults>1</adults>
<kids>1</kids>
<k1a>5</k1a>
</room>
</rooms>
</hotel>
</hotels>
<flights>
<flight>
<quoteid>1885e28d-5198-4dd5-92e6-6cee14a66b1b</quoteid>
<ratekey>bc1b40db-b0fb-40ff-92b3-6b7cde0d8685</ratekey>
<passengers>
<passenger>
<isadult>Y</isadult>
<agechild></agechild>
<firstname>Prueba</firstname>
<lastname>Prueba</lastname>
<daybirthday>05</daybirthday>
<monthbirthday>06</monthbirthday>
<yearbirthday>1905</yearbirthday>
<numberfrecuent></numberfrecuent>
<idfrecuent></idfrecuent>
<naturalperson>
<type></type>
<number></number>
</naturalperson>
</passenger>
</passengers>
<contacts>
<contact>
<firstname>Prueba</firstname>
<lastname>Prueba</lastname>
<email></email>
<phones>
<phone>
<type>1</type>
<number>(+52)654654646</number>
</phone>
</phones>
</contact>
</contacts>
</flight>
</flights>
<shuttles>
<shuttle>
<shuttleid>599</shuttleid>
<shuttletype>R</shuttletype>
<adults>2</adults>
<kids>0</kids>
<airportarrival>Aeropuerto Internacional de Cancun </airportarrival>
<airlinearrival>AC</airlinearrival>
<datearrival>20140501</datearrival>
<hourarrival>18:00</hourarrival>
<flightarrival>123</flightarrival>
<airlinedeparture>PU</airlinedeparture>
<datedeparture>20140502</datedeparture>
<hourdeparture>04:00</hourdeparture>
<flightdeparture>456</flightdeparture>
<hotelid>640</hotelid>
<amount>724.8</amount>
</shuttle>
</shuttles>
<insurances>
<insurance>
<insuranceid>12</insuranceid>
<adults>2</adults>
<children>0</children>
<amount>105.1049</amount>
<ratekey>4f2b132f-6663-427a-aa75-61c5d8e37635</ratekey>
</insurance>
</insurances>
<cars>
<car>
<agency>2</agency>
<sipp>AR133</sipp>
<amount>869.76</amount>
<brancharrival>139</brancharrival>
<airportarrival>CUN</airportarrival>
<datearrival>20140501</datearrival>
<hourarrival>12:00</hourarrival>
<branchdeparture>139</branchdeparture>
<airportdeparture>CUN</airportdeparture>
<datedeparture>20140502</datedeparture>
<hourdeparture>12:00</hourdeparture>
</car>
</cars>
<tours>
<tour>
<tourid>413</tourid>
<serviceid>1</serviceid>
<cityid>NOCIUDAD</cityid>
<adults>2</adults>
<kids>0</kids>
<datetour>20140711</datetour>
<hotelname>Cancun Clipper Club, Cancun Zona Hotelera Punta Cancun, Mexico</hotelname>
<timetour>00:00</timetour>
<amount>2035.62</amount>
<dutypercent>0</dutypercent>
</tour>
</tours>
<payments>
<cardpayment>
<type>86</type>
<bank>BC3</bank>
<number>XXXXXXXXXXXXXX</number>
<securitycode>1212</securitycode>
<expirationmonth>03</expirationmonth>
<expirationyear>2018</expirationyear>
<holdername>prueba prueba</holdername>
<address>bonampak 4</address>
<city>cancun</city>
<state>QROO</state>
<country>MX</country>
<zip>77500</zip>
<amount>12346.51</amount>
</cardpayment>
</payments>
</Request>';


$funcion = "Book";
ini_set('soap.wsdl_cache_enabled', 0);
$wsdl = 'http://testxml.e-tsw.com/AffiliateService/AffiliateService.svc?Wsdl';
$client = new SoapClient($wsdl);
$xml_reserva = simplexml_load_string($xml, NULL, LIBXML_NOCDATA);
try {
    $respuesta     = $client->__soapCall($funcion, array('Parameters' => $xml_reserva));
    } catch (SoapFault $exception) {
        echo $exception->getMessage();

    }

As you may notice, the code is the same. Just change the xml and the "GetHotels" function to "Book". Next the document wsdl

link

I appreciate your help to get out of this trap that has me testing for several days. Maybe I'm focusing badly on this whole thing, because I'm not an expert on Soap.

Greetings and thanks, Luis

    
asked by Luis Beltrán Vásquez Sequera 15.04.2018 в 20:09
source

2 answers

0

I did what you recommended @solrac converting the xml into an array and now it is an "unknown error" that throws me

Next the code, with the arrangement:

    try{
     $client = new SoapClient('http://testxml.e-tsw.com/AffiliateService/AffiliateService.svc?Wsdl', ['trace' => 1, 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE, "compression" => SOAP_COMPRESSION_ACCEPT, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS]);

$parametros = Array
(
    'attributes' => Array
        (
            'Type' => 'Reservation',
            'Version' => '1.0'
        ),

    'affiliateid' => 'AF-TVOD',
    'language' => 'esp',
    'currency' => 'PE',
    'uid' => 'm2r32b14es10socxtxs4y4ht',
    'ip' => '201.147.113.232',
    'firstname' => 'prueba',
    'lastname' => 'prueba',
    'emailaddress' => '[email protected]',
    'country' => 'MX',
    'address' => 'bonampak 4',
    'city' => 'cancun',
    'state' => 'QROO',
    'zip' => '77500',
    'total' => '12346.51',
    'naturalperson' => Array
        (
            'gender' => Array
                (
                ),

            'nationality' => Array
                (
                ),

            'number' => Array
                (
                ),

            'type' => Array
                (
                )

        ),

    'legalperson' => Array
        (
            'businessname' => Array
                (
                ),

            'number' => Array
                (
                ),

            'type' => Array
                (
                )

        ),

    'phones' => Array
        (
            'phone' => Array
                (
                    'type' => '2',
                    'number' => '9981454221'
                )

        ),

    'hotels' => Array
        (
            'hotel' => Array
                (
                    'hotelid' => '100',
                    'roomtype' => 'SUPOV',
                    'mealplan' => 'EP',
                    'datearrival' => '20141113',
                    'datedeparture' => '20141115',
                    'couponid' => Array
                        (
                        ),

                    'marketid' => 'INTER',
                    'contractid' => '2',
                    'dutypercent' => '0',
                    'rooms' => Array
                        (
                            'room' => Array
                                (
                                    'amount' => '985.34',
                                    'status' => 'AV',
                                    'ratekey' => '90cba867-f916-4fb9-8cb4-ec925ded0fb3',
                                    'adults' => '1',
                                    'kids' => '1',
                                    'k1a' => '5'
                                )

                        )

                )

        ),

    'flights' => Array
        (
            'flight' => Array
                (
                    'quoteid' => '1885e28d-5198-4dd5-92e6-6cee14a66b1b',
                    'ratekey' => 'bc1b40db-b0fb-40ff-92b3-6b7cde0d8685',
                    'passengers' => Array
                        (
                            'passenger' => Array
                                (
                                    'isadult' => 'Y',
                                    'agechild' => Array
                                        (
                                        ),

                                    'firstname' => 'Prueba',
                                    'lastname' => 'Prueba',
                                    'daybirthday' => '05',
                                    'monthbirthday' => '06',
                                    'yearbirthday' => '1905',
                                    'numberfrecuent' => Array
                                        (
                                        ),

                                    'idfrecuent' => Array
                                        (
                                        ),
                                    'naturalperson' => Array
                                        (
                                            'type' => Array
                                                (
                                                ),

                                            'number' => Array
                                                (
                                                ),

                                        )

                                )

                        ),

                    'contacts' => Array
                        (
                            'contact' => Array
                                (
                                    'firstname' => 'Prueba',
                                    'lastname' => 'Prueba',
                                    'email' => Array
                                        (
                                        ),

                                    'phones' => Array
                                        (
                                            'phone' => Array
                                                (
                                                    'type' => '1',
                                                    'number' => '(+52)654654646',
                                                )

                                        )

                                )

                        )

                )

        ),

    'shuttles' => Array
        (
            'shuttle' => Array
                (
                    'shuttleid' => '599',
                    'shuttletype' => 'R',
                    'adults' => '2',
                    'kids' => '0',
                    'airportarrival' => 'Aeropuerto Internacional de Cancun', 
                    'airlinearrival' => 'AC',
                    'datearrival' => '20140501',
                    'hourarrival' => '18:00',
                    'flightarrival' => '123',
                    'airlinedeparture' => 'PU',
                    'datedeparture' => '20140502',
                    'hourdeparture' => '04:00',
                    'flightdeparture' => '456',
                    'hotelid' => '640',
                    'amount' => '724.8',
                )

        ),

    'insurances' => Array
        (
            'insurance' => Array
                (
                    'insuranceid' => '12',
                    'adults' => '2',
                    'children' => '0',
                    'amount' => '105.1049',
                    'ratekey' => '4f2b132f-6663-427a-aa75-61c5d8e37635',
                )

        ),

    'cars' => Array
        (
            'car' => Array
                (
                    'agency' => '2',
                    'sipp' => 'AR133',
                    'amount' => '869.76',
                    'brancharrival' => '139',
                    'airportarrival' => 'CUN',
                    'datearrival' => '20140501',
                    'hourarrival' => '12:00',
                    'branchdeparture' => '139',
                    'airportdeparture' => 'CUN',
                    'datedeparture' => '20140502',
                    'hourdeparture' => '12:00',
                )

        ),

    'tours' => Array
        (
            'tour' => Array
                (
                    'tourid' => '413',
                    'serviceid' => '1',
                    'cityid' => 'NOCIUDAD',
                    'adults' => '2',
                    'kids' => '0',
                    'datetour' => '20140711',
                    'hotelname' => 'Cancun Clipper Club, Cancun Zona Hotelera Punta Cancun, Mexico',
                    'timetour' => '00:00',
                    'amount' => '2035.62',
                    'dutypercent' => '0',
                )

        ),

    'payments' => Array
        (
            'cardpayment' => Array
                (
                    'type' => '86',
                    'bank' => 'BC3',
                    'number' => 'XXXXXXXXXXXXXX',
                    'securitycode' => '1212',
                    'expirationmonth' => '03',
                    'expirationyear' => '2018',
                    'holdername' => 'prueba prueba',
                    'address' => 'bonampak 4',
                    'city' => 'cancun',
                    'state' => 'QROO',
                    'country' => 'MX',
                    'zip' => '77500',
                    'amount' => '12346.51',
                )

        )

);

    $salida = $client->Book($parametros);

    } catch (Exception $exc) {
        echo "<pre>";
    print_r($exc);
    echo "</pre>";
    // echo htmlspecialchars(print_r($exc, true));
    }
    echo "respuesta del ws";
    echo "<pre>";
    print_r($salida);
    echo "</pre>";

The exception that it shows is the following:

stdClass Object
(
    [BookResult] => stdClass Object
        (
            [confirmationid] => 0
            [total] => 0
            [Error] => stdClass Object
                (
                    [Id] => 600
                    [Description] => An unknown error has ocurred
                    [Data] => Affiliate Service
                )

        )

)
    
answered by 16.04.2018 в 03:07
0

Activate the trace to know what happens with your request, activate the exceptions to stop the flow in your try / catch block and finally, handle the input data in an array instead of the complete XML to make it easier.

You can try something like this:

try{
 $client = new SoapClient('http://testxml.e-tsw.com/AffiliateService/AffiliateService.svc?Wsdl', ['trace' => 1, 'exceptions' => true, 'cache_wsdl' => WSDL_CACHE_NONE, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS]);

 $parametros = [
  'affiliateid' => 'AF-AVV',
  'language'=>'esp',
  'currency'=>'PE',
  'uid'=>'m2r32b14es10socxtxs4y4ht',

  'hotels' => [
   'hotel' => [
    'hotelid' => 100,
    ...
   ],
   ...
  ],

  'total'=>'123456.51'
   ...
 ];

 $client->Book($parametros);

} catch (Exception $exc) {
 echo htmlspecialchars(print_r($exc, true));
}

At the end of the day, the object of using a WSDL to feed the SOAP client is that PHP can decide where and how to interpret the input data according to that document. If someone is missing or is badly positioned, the SOAP client will let you know.

    
answered by 15.04.2018 в 21:52