Hi All

I'm just starting to try and cope with soap, and was getting on ok, until I realised that the SOAP request needed elements of the same name, which associative arrays obviously don't like.

example [cut-down abit, but you should get the idea]:

This is a simple soap request, nice:

<?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Body>
<QASearch xmlns="http://www.qas.com/web-2005-10">
<Country>GBN</Country>
<Engine Flatten="true" PromptSet="Default">Singleline</Engine>
<Layout>experian</Layout>
<Search type="First">sw40ql</Search>
</QASearch>
</soapenv:Body>

which I can construct using:

$do_search = array(
'Country' => 'GBR',
'Engine' => array ('' => 'Singleline', 'Flatten' => true, 'PromptSet' => 'Default'),
'Layout' => 'experian',
'Search' => array ('
' => 'sw40ql', type => 'First');

and call:

$response_DoSearch = $client-> DoSearch($do_search);

ALL WORKS FINE, I GET A RESPONSE.

However,

If the SOAP request requires elements of the same name, like the Search element:

<?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Body>
<QASearch xmlns="http://www.qas.com/web-2005-10">
<Country>GBN</Country>
<Engine Flatten="true" PromptSet="Default">Singleline</Engine>
<Layout>experian</Layout>
<Search type="First">sw40ql</Search>
<Search type="Second">sw41ql</Search>
<Search type="Third">sw42ql</Search>
<Search type="Fourth">sw43ql</Search>
<Search type="Fifth">sw44ql</Search>
</QASearch>
</soapenv:Body>

I am at a loss how to construct this.

I've tried:

$do_search = array(
'Country' => 'GBR',
'Engine' => array ('' => 'Singleline', 'Flatten' => true, 'PromptSet' => 'Default'),
'Layout' => 'experian',
new SoapParam(array('type' => 'first','
' => 'sw40ql'),'Search'),
new SoapParam(array('type' => 'second','' => 'sw41ql'),'SearchTerm'),
new SoapParam(array('type' => 'third','
' => 'sw42ql'),'SearchTerm'),
new SoapParam(array('type' => 'fourth','' => 'sw43ql'),'SearchTerm'),
new SoapParam(array('type' => 'fifth','
' => 'sw44ql'),'SearchTerm'));

which, using print_r, constructs the following [but the server doesn't like the contstruction]. I tried using new soapvar too, but not sure you can add attributes.

Array (

[Country] => GBR
[Engine] => Array ( [_] => Singleline [Flatten] => 1 [PromptSet] => Default)
[Layout] => experian

[0] => SoapParam Object (
[param_name] => Search
[param_data] => Array ( [_] => sw40ql [Key] => first))

[1] => SoapParam Object (
[param_name] => Search
[param_data] => Array ( [_] => sw41ql [Key] => second))

[2] => SoapParam Object (
[param_name] => Search
[param_data] => Array ( [_] => sw42ql [Key] =>third))

[3] => SoapParam Object (
[param_name] => Search
[param_data] => Array ( [_] => sw43ql [Key] => fourth))

[4] => SoapParam Object (
[param_name] => Search
[param_data] => Array ( [_] => sw44ql [Key] => fifth))
)

Any ideas on how else to approach this ??

HELP!

Thanks

    Do you really need to name your array keys? Just keeping your search terms ordered should produce an XML on format
    <param0 xsi:type="xsd:string">sw40ql</param0>
    <param1 xsi:type="xsd:string">sw41ql</param1>

    And if your doSearch function needs an associative array, try naming your keys Search0, Search1 etc.

      Thanks for your reply.

      Unfortunately, the WSDL request exists on the server, and I can't amend it, so I think I need to construct it as per the example for it to work, although the SearchTerm elements, are within a SearchSpec element:

      <SearchSpec>
      <SearchTerm type="First">sw40ql</Search>
      <SearchTerm type="Second">sw41ql</Search>
      <SearchTerm type="Third">sw42ql</Search>
      <SearchTerm type="Fourth">sw43ql</Search>
      <SearchTerm type="Fifth">sw44ql</Search>
      </SeachSpec>

      FYI, this is an Experian QAS request, if anyone has got it working with PHP before.

      I will give it a go [numbering SearchTerm1,SearchTerm2 etc], but I doubt it will like it. Will let you know.

      Thanks

        In that case I'm guessing the problem is that you do not wrap your search terms in an array as per their specification.

        ,
        Search => array(
        	array('type' => 'first','_' => 'sw40ql'),
        	array('type' => 'second','_' => 'sw41ql'),
        	array('type' => 'third','_' => 'sw42ql'),
        	array('type' => 'fourth','_' => 'sw43ql'),
        	array('type' => 'fifth','_' => 'sw44ql')
        )
        

          thanks for sticking with me!

          Ah, so, something like:

          $do_search = array( 
          'Country' => 'GBR', 
          'Engine' => array ('_' => 'Singleline', 'Flatten' => true, 'PromptSet' => 'Default'),
          'Layout' => 'experian', 
          'SearchSpec' => array( 
              array('type' => 'first','_' => 'sw40ql'), 
              array('type' => 'second','_' => 'sw41ql'), 
              array('type' => 'third','_' => 'sw42ql'), 
              array('type' => 'fourth','_' => 'sw43ql'), 
              array('type' => 'fifth','_' => 'sw44ql') 
          )); 

          I'm not with my code [at home now and forgot to upload] but will check it first thing in the morning.

          Obviously, the first thing I tried was this, but of course, it only sends the last element:

          $do_search = array( 
          'Country' => 'GBR', 
          'Engine' => array ('_' => 'Singleline', 'Flatten' => true, 'PromptSet' => 'Default'),
          'Layout' => 'experian', 
          'SeachSpec' => array (
          'SearchTerm' => array('type' => 'first','_' => 'sw40ql'), 
          'SearchTerm' => array('type' => 'second','_' => 'sw41ql'), 
          'SearchTerm' => array('type' => 'third','_' => 'sw42ql'), 
          'SearchTerm' => array('type' => 'fourth','_' => 'sw43ql'), 
          'SearchTerm' => array('type' => 'fifth','_' => 'sw44ql') 
          )); 

          Thanks!

            I think you would want a multi-dimensional array:

            array(
            ...
            'SearchSpec' => array(
              'sw40ql', 'sw41ql', 'etc' ),
            ...
            )
            

            The keys should not be important as the WSDL file will define SearchSpec as a complex type with n occurances of SearchTerm.

              Hi Shrike; Thanks, but as there are attributes to SearchTerm, I think I'd need the array of arrays as above wouldn't I ? Its encouraging that you think WSDL will define SearchSpec and what it expects for me. My first encounter with WSDL was a few days ago, so am still finding my feet.

              $do_search = array(
              'Country' => 'GBR',
              'Engine' => array ('' => 'Singleline', 'Flatten' => true, 'PromptSet' => 'Default'),
              'Layout' => 'experian',
              'SearchSpec' => array(
              array('type' => 'first','
              ' => 'sw40ql'),
              array('type' => 'second','' => 'sw41ql'),
              array('type' => 'third','
              ' => 'sw42ql'),
              array('type' => 'fourth','' => 'sw43ql'),
              array('type' => 'fifth','
              ' => 'sw44ql')
              ));

                Yep correct, I was just pointing out that the keys of the array 'SearchSpec' were not relevant. Perhaps I've just reiterated what johanafm said 🙂

                  Morning.

                  Gave it a go, and it constructed beautifully.

                  Thanks johanafm and shrike, that should see me through nicely.

                  All the best.

                    Write a Reply...