Loading ...
Sorry, an error occurred while loading the content.

Got a Problem in building a WSDLcall in Perl SOAP::Lite from working PHP call...

Expand Messages
  • olli_perl
    Hey folks, there is a good working PHP WSDL call-example which I want to redo in Perl using SOAP::Lite. My other calls built in Perl work very well, but that
    Message 1 of 2 , Mar 7, 2010
    View Source
    • 0 Attachment
      Hey folks,
      there is a good working PHP WSDL call-example which I want to redo in Perl using SOAP::Lite. My other calls built in Perl work very well, but that silly one won't. I'm working so so long on it without result... Hope someone can help me :)

      These scripts shall get some informations about the given carIds, e.g. number of cylinders etc.


      At first that working PHP example:
      #############################################
      <?php
      require_once('lib/nusoap.php');
      $client = new nusoap_client('http://webservicepilot.tecdoc.net/pegasus-2-0/wsdl/TecdocToCat',true);

      $client->soap_defencoding = 'UTF-8';
      $providerid = 555; //(555 won't work...)
      $paramneu = array('provider'=>$providerid,
      'axles' => true,
      'cabs' => true,
      'carIds' => array('empty' => false , 'array' => array(19016)),
      'countriesCarSelection' => de,
      'country'=>de,
      'countryGroupFlag'=>false,
      'countryUserSetting'=>de,
      'motorCodes'=>true,
      'secondaryTypes'=>true,
      'vehicleDetails2'=>true,
      'vehicleTerms'=>true,
      'wheelbases'=>true,
      'lang'=>de
      ); // set request

      $result = $client->call('getVehicleByIds2', array('in0' => $paramneu));

      if ($client->fault) {
      echo '<h2>Fault</h2><pre>';
      print_r($result);
      echo '</pre>';
      } else {
      // Check for errors
      $err = $client->getError();
      if ($err) { // Display the error
      echo '<h2>Error</h2><pre>' . $err . '</pre>';
      } else {
      // show the informations
      echo '<h2>Results:</h2><pre >';
      print_r($result);
      echo '</pre>';
      }
      }
      unset($client);
      ?>
      ############################################

      ...and now my poor Perl plagiate:
      ############################################
      #!/usr/bin/perl -w
      #!/usr/bin/composite

      use CGI::Carp 'fatalsToBrowser';
      use SOAP::Lite;
      use Data::Dumper;
      use warnings;

      print "Content-type: text/html \n\n";
      my $soap = SOAP::Lite
      -> uri('http://webservicepilot.tecdoc.net/pegasus-2-0/wsdl/TecdocToCat')
      -> proxy('http://webservicepilot.tecdoc.net/pegasus-2-0/services/TecdocToCat');

      $providerid = 555; #(555 won't work...)
      my $som = $soap->getVehicleByIds2( {
      axles => true,
      cabs => true,
      carIds => \(
      empty => false,
      array => [19016]
      ),
      country => "de",
      countriesCarSelection => "de",
      countryGroupFlag => false,
      countryUserSetting => false,
      lang => "de",
      motorCodes => true,
      provider => $providerid,
      secondaryTypes => true,
      vehicleDetails2 => true,
      vehicleTerms => true,
      wheelbases => true
      });

      if ($som->fault) {
      print $som->faultstring;
      } else {
      my $soap_result = $som->result;
      print Dumper $soap_result;
      }
      #####################################################

      I know the problem is that carIds array. First I tried just to send my one ID 19016 as a simple integer / long. Then i got that PHP example and saw that there has to be an array, with as its first entry an element "empty" which is 'false' to say there will follow some entries. Next one is the element "array" with an array of carIds (in my case there is only one carID). It is said that this is described in the service, but there they only say a LongList is needed:
      <element name="carIds" nillable="true" type="tns1:LongList"/>
      (Taken from http://webservicepilot.tecdoc.net/pegasus-2-0/wsdl/TecdocToCatWL)

      So how can I rebuild that needed array(s) so that this call will be successful?
      Hope somebody can help me... Please :)

      All the best
      Olli
    • Martin Busik
      Hi, ... Yepp. It is a good idea to find out, what xml-requests do php and perl generate and then to find out how to manage it to create what s needed. I m a
      Message 2 of 2 , Mar 9, 2010
      View Source
      • 0 Attachment
        Hi,

        > $paramneu = array('provider'=>$providerid,
        > 'axles' => true,
        > 'cabs' => true,
        > 'carIds' => array('empty' =>
        > false , 'array' => array(19016)),
        > 'countriesCarSelection' => de,
        > 'country'=>de,
        > 'countryGroupFlag'=>false,
        > 'countryUserSetting'=>de,
        > 'motorCodes'=>true,
        > 'secondaryTypes'=>true,
        > 'vehicleDetails2'=>true,
        > 'vehicleTerms'=>true,
        > 'wheelbases'=>true,
        > 'lang'=>de
        > ); // set request
        >
        > $result = $client->call('getVehicleByIds2', array('in0' =>
        > $paramneu));

        > I know the problem is that carIds array.

        Yepp. It is a good idea to find out, what xml-requests do php and perl
        generate and then to find
        out how to manage it to create what's needed.

        I'm a fan of creating the request on my own, i.e. create an object-tree of
        SOAP::Data-Instances.

        I've used following before - with the PHP built in webservice api. I
        suppose, nusoap.php uses the same (at least you get an idea):

        $SOAPENC_PREFIX =
        $proxy->serializer->find_prefix(SOAP::Constants::URI_SOAP11_ENC());
        $XMLSOAP_PREFIX = $proxy->serializer->find_prefix($SOAP::Constants::NS_APS);
        $client->call('Method',_array($e1,$e2,$e3,...))

        sub _array {
        my ($name,@items) = @_;

        return SOAP::Data->name($name)->type($SOAPENC_PREFIX.":Array")->value(
        \SOAP::Data->value( (map { _item($_) } @items) )
        );
        }

        sub _item {
        my ($value) = @_;

        return _map("item",$value) if ref($value) eq "HASH";
        return _array("item",@$value) if ref($value) eq "ARRAY";
        return SOAP::Data->name("item")->value($value);
        }

        sub _map {
        my ($name,$hash) = @_;

        return SOAP::Data->name($name)->type($XMLSOAP_PREFIX.":Map")->value(
        \SOAP::Data->value(
        map { SOAP::Data->name("item")->value( \SOAP::Data->value(
        SOAP::Data->name("key")->value($_),
        SOAP::Data->name("value")->value($hash->{$_})
        ))
        } keys %$hash
        )
        );
        }

        Array elements might be scalar values, arrays or hasharrays (maps), so it
        should work with following php constructs:

        $e1 = "scalar";
        $e2 = array(1,2,"aaa")
        $e3 = array("a" => 1, "b" => 2)

        Cheers,
        Martin
      Your message has been successfully submitted and would be delivered to recipients shortly.