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

dynamically build SOAP envelope with Perl ???

Expand Messages
  • jonthorwilliams
    I know that there must be a way to accomplish this. I am also posting my error message below. stated simply, i cannot get this to work, because it wont take a
    Message 1 of 3 , May 27 10:57 AM
    • 0 Attachment
      I know that there must be a way to accomplish this. I am also
      posting my error message below.

      stated simply, i cannot get this to work, because it wont take a
      straight string argument:

      my $som = $soap->getStateName( $argstring );

      *******************
      #!perl -w

      use strict;
      use SOAP::Lite +'trace';

      my $soap = SOAP::Lite
      -> uri('/examples')
      -> on_action(sub { sprintf '"%s"', shift })
      -> proxy('http://superhonker.userland.com/');

      my %headers = ("MyHeader"=>"test");
      my %body = ("statenum"=>49);
      my $argstring;

      #print Dumper(%headers);
      print "\n--------\n";
      while( my ($key, $value) = each(%headers) ) {
      #print "$key => $value\n";
      $argstring = $argstring."SOAP::Header->name('$key')->type
      (string => '$value'),";
      }
      while( my ($key, $value) = each(%body) ) {
      #print "$key => $value\n";
      $argstring = $argstring."SOAP::Data->name('$key')->type
      (string => '$value'),";
      }

      $argstring = substr($argstring, 0, -1);
      print $argstring."\n\n";

      my $som = $soap->getStateName( $argstring ); # THIS does not
      work !!!???

      print "\n-----\n";

      if ($som->match(SOAP::SOM::envelope)) {
      print "Res=".$som->result."\n";
      print "NS=".$som->namespaceuriof('Body')."\n";
      } else {
      print "nothing here\n";
      }


      *******************
      my debug output in my console:

      C:\Temp>test.pl
      SOAP::Transport::new: ()
      SOAP::Serializer::new: ()
      SOAP::Deserializer::new: ()
      SOAP::Parser::new: ()
      SOAP::Lite::new: ()
      SOAP::Transport::HTTP::Client::new: ()

      --------
      SOAP::Header->name('MyHeader')->type(string => 'test'),SOAP::Data-
      >name('statenum')->type(string => '49')

      SOAP::Lite::call: ()
      SOAP::Serializer::envelope: ()
      SOAP::Serializer::envelope: getStateName SOAP::Header->name
      ('MyHeader')->type(string => 'test'),SOAP::Data->name('statenum')-
      >type(string => '49')
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Data::new: ()
      SOAP::Transport::HTTP::Client::send_receive: HTTP::Request=HASH
      (0x1de51a4)
      SOAP::Transport::HTTP::Client::send_receive: POST
      http://superhonker.userland.com/
      Accept: text/xml
      Accept: multipart/*
      Content-Length: 613
      Content-Type: text/xml; charset=utf-8
      SOAPAction: "/examples"

      <?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-
      ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:
      encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-
      ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs
      i="http://www.w3.org/1999/XMLSchema-instance"
      xmlns:xsd="http://www.w3.org/1999/XMLSchema"><SOAP-
      ENV:Body><namesp1:getStateNa
      me xmlns:namesp1="/examples"><c-gensym3
      xsi:type="xsd:string">SOAP::Header->name('MyHeader')->type(string
      => 'test'),SOAP::Da
      ta->name('statenum')->type(string => '49')</c-
      gensym3></namesp1:getStateName></SOAP-ENV:Body></SOAP-ENV:Envelope>
      SOAP::Transport::HTTP::Client::send_receive: HTTP::Response=HASH
      (0x2331fb8)
      SOAP::Transport::HTTP::Client::send_receive: HTTP/1.1 500 (Internal
      Server Error) Server Error
      Connection: close
      Date: Mon, 27 May 2002 17:54:38 GMT
      Server: UserLand Frontier/7.0.1-WinNT
      Content-Length: 569
      Client-Date: Mon, 27 May 2002 17:57:30 GMT
      Client-Peer: 64.14.1.89:80

      <?xml version="1.0"?>
      <SOAP-ENV:Envelope SOAP-
      ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      xmlns:SOAP-ENV="http://schemas.xmlsoap
      org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema"
      xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
      <SOAP-ENV:Body>
      <SOAP-ENV:Fault>
      <faultcode>SOAP-ENV:Client</faultcode>
      <faultstring>Can't call the script
      "getStateName" because it doesn't define a par
      ameter named "c-gensym3"</faultstring>
      </SOAP-ENV:Fault>
      </SOAP-ENV:Body>
      </SOAP-ENV:Envelope>

      SOAP::Deserializer::deserialize: ()
      SOAP::Parser::decode: ()
      SOAP::SOM::new: ()

      -----
      Use of uninitialized value in concatenation (.) or string at
      C:\Temp\test.pl line 34.
      Res=
      NS=http://schemas.xmlsoap.org/soap/envelope/
      SOAP::Lite::DESTROY: ()
      SOAP::Serializer::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Data::DESTROY: ()
      SOAP::Transport::DESTROY: ()
      SOAP::Transport::HTTP::Client::DESTROY: ()
      SOAP::Deserializer::DESTROY: ()
      SOAP::SOM::DESTROY: ()
      SOAP::Parser::DESTROY: ()
    • Duncan Cameron
      ... Why do you think that it should? Your argstring is a piece of Perl code that needs to be evaluated. If you want to build a SOAP message dynamically then
      Message 2 of 3 , May 27 12:36 PM
      • 0 Attachment
        On 2002-05-27 jonthorwilliams wrote:
        >I know that there must be a way to accomplish this.

        >stated simply, i cannot get this to work, because it wont take a
        >straight string argument:
        >
        >my $som = $soap->getStateName( $argstring );

        Why do you think that it should? Your argstring is a piece of Perl code that needs
        to be evaluated.
        If you want to build a SOAP message dynamically then something like this is probably a
        better approach:

        while( my ($key, $value) = each(%body) ) {
        push @params, SOAP::Data->name($key)->type(int => $value);
        }

        my $som = $soap->getStateName( @params );


        Regards,
        Duncan Cameron
      • jonthorwilliams
        thanks Duncan... your answer to my question worked perfectly... ill attach my sourcecode. it reads in a text file, builds a SOAP envelope out of the file ,
        Message 3 of 3 , May 28 10:20 AM
        • 0 Attachment
          thanks Duncan... your answer to my question worked perfectly... ill
          attach my sourcecode. it reads in a text file, builds a SOAP
          envelope out of the file , sends the request, and prints out the
          answer from the response envelope.

          jon

          ****************

          #!perl -w

          use strict;
          use SOAP::Lite +'trace';

          my %headers;
          my %body;
          my $record;
          my @thisline;
          my @params;

          my $apifile = shift || die "Enter a API file name as an argument.\n";

          my $soap = SOAP::Lite
          -> uri('http://www.domainname.com')
          -> proxy('http://localhost:8080/'); #proxy to MSSoapTrace

          open (APIFILE, $apifile) || die "couldn't open the file!";
          while ($record = <APIFILE>) {

          chomp($record);

          if ( substr( $record, 0, 3 ) eq '_H_' ) {
          @thisline = split(/=/, $record);
          my $hashkey = $thisline[0];
          my $key = substr($hashkey, 3);
          my $val = $thisline[1];
          $headers{$key} = $val;
          } elsif ( substr( $record, 0, 1 ) eq '#' ) {
          } elsif ( $record eq '' ) {
          } elsif ( $record ) {
          @thisline = split(/=/, $record);
          $body{$thisline[0]}= $thisline[1];
          my $key = $thisline[0];
          my $val = $thisline[1];
          $body{$key} = $val;
          }

          }
          close(APIFILE);

          print "\n--------\n";

          while( my ($key, $value) = each(%headers) ) {
          push @params, SOAP::Header->name($key)->type(string =>
          $value);
          }

          while( my ($key, $value) = each(%body) ) {
          push @params, SOAP::Data->name($key)->type(string => $value);
          }

          my $som = $soap->CatLookup( @params );

          print "Res=".$som->result."\n\n";
          print "--------\n\n";



          --- In soaplite@y..., Duncan Cameron <dcameron@b...> wrote:
          > On 2002-05-27 jonthorwilliams wrote:
          > >I know that there must be a way to accomplish this.
          >
          > >stated simply, i cannot get this to work, because it wont take a
          > >straight string argument:
          > >
          > >my $som = $soap->getStateName( $argstring );
          >
          > Why do you think that it should? Your argstring is a piece of Perl
          code that needs
          > to be evaluated.
          > If you want to build a SOAP message dynamically then something like
          this is probably a
          > better approach:
          >
          > while( my ($key, $value) = each(%body) ) {
          > push @params, SOAP::Data->name($key)->type(int => $value);
          > }
          >
          > my $som = $soap->getStateName( @params );
          >
          >
          > Regards,
          > Duncan Cameron
        Your message has been successfully submitted and would be delivered to recipients shortly.