MR.GEWA
MR.GEWA

Reputation: 873

Why php's soapCall gives string conversion error?

 // Set username and password
    $ih_soap_user= $this->config->item('interUser');
    $ih_soap_pass=$this->config->item('interPass');


    //echo $ih_soap_user.':P:'.$ih_soap_pass;
    // Set soap namespace
    $ih_soap_ns = 'http://www.interhome.com/webservice';
    // Create new instance of SoapClient with the interhome web service URL
    $client = new
    SoapClient($this->config->item('interSoap'),array('trace'=>'1'));
    // Create new soap header and set username and password
    $header = new SoapHeader($ih_soap_ns,
            'ServiceAuthHeader',
    array('Username' => $ih_soap_user,'Password' =>
    $ih_soap_pass),
    true
    );
    // Prepare p// Prepare parameters


  $params = array('inputValue' =>array(
        'Page'=>$page,
        'PageSize'=>'10',
        'OrderDirection'=>'Ascending',//Descending
        'OrderBy'=>'Price',//Favorite,Place
        'LanguageCode'=>'EN',
        'CurrencyCode'=>'EUR',

        'CountryCode'=>trim($ajaxSearchCountryCode),
        'RegionCode'=>trim($ajaxSearchRegionCode),
        'PlaceCode'=>$ajaxSearchPlaceCode,
        'CheckIn'=> $ajaxSearchCheckinDate,
        'Duration'=>'7',
       'ThemeFilter'=>$ajaxSearchTheme,
       'HouseApartmentType'=>array('House'=>'House'),
       'SpecialOffer'=>'AnySpecialOffer',
         'PaxMin'=>'1',
         'PaxMax'=>'',
          'RoomsMin'=>'1',
         'RoomsMax'=>'',



    ) );



    try{
    $result = $client->__soapCall("Search",array('parameters'=> $params),null,$header);

Hi guys..Any Idea why this call when I pass any not empty array, as for example ,as I made for 'HouseApartmentType', returns this error

A PHP Error was encountered

Severity: Notice

Message: Array to string conversion

Filename: controllers/houses.php

Line Number: 269

And when it's only empty array or a string the soap call function is working... I need to pass array of options to one parameter....

LINE 269 is

$result = $client->__soapCall("Search",array('parameters'=> $params),null,$header);

Upvotes: 1

Views: 8244

Answers (2)

Fredde
Fredde

Reputation: 31

This is probably solved already, but I also had problems with this and I thought I should post here when I finally found the solution. (The solution is not nusoap, it throws the same error.)

The error only seems to come from the soapCall call generation, it really is the Web Service that causes it. When you run __soapCall, it first asks the server which datatypes the parameters should have and then tries to comply. So if you try to feed an array when the service expects a string, it will do the array to string conversion when the request is generated.

Upvotes: 3

Ibu
Ibu

Reputation: 43810

i think you should look at the manual how a soapcall work:

$params = array(
     'Page'=>$page,
     'PageSize'=>'10',
     'OrderDirection'=>'Ascending',//Descending
     'OrderBy'=>'Price',//Favorite,Place
     'LanguageCode'=>'EN',
     'CurrencyCode'=>'EUR',
     'CountryCode'=>trim($ajaxSearchCountryCode),
     'RegionCode'=>trim($ajaxSearchRegionCode),
     'PlaceCode'=>$ajaxSearchPlaceCode,
     'CheckIn'=> $ajaxSearchCheckinDate,
     'Duration'=>'7',
     'ThemeFilter'=>$ajaxSearchTheme,
     'HouseApartmentType'=>'House', // changed to string instead of array
     'SpecialOffer'=>'AnySpecialOffer',
     'PaxMin'=>'1',
     'PaxMax'=>'', 
     'RoomsMin'=>'1', 
     'RoomsMax'=>'' );  

i simplified the array and you should test it and look if this is the kind of result you are looking for.

Also look for ordering errors like the example shown in php.net

Upvotes: 1

Related Questions