three18ti has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks

This is a continuation of last nights question [SOLVED][SOAP::Lite] Obtain request body before request is sent? but I think I need to step back and understand what's going on before moving forward.

First of all, I think what I'm really after is the request envelope. I'd like to be able to print or otherwise store in a variable the XML markup in the envelope. Second of all, I need to modify the HTTP request header (not the XML header as I proposed in the above linked thread). I had my terms mixed up last night but I think I'm starting to understand better.

Anyway. What I'm really after is what happens when you call $client->my_api_method(\%params); where is the XML actually built?

Here is the code I'm working with

<#!/usr/bin/env perl use strict; use warnings; use 5.010; use LWP::UserAgent; use SOAP::Lite; use LWP::Debug; LWP::Debug::level('+'); SOAP::Lite->import(+trace => ' +all'); my $client = SOAP::Lite->proxy($proxy) ->ns($namespace, 'foo') # I'm not sure I understand this. ->uri($uri) ->on_action(sub { sprintf '%s', $_[0] }) ->on_fault(sub { my($soap, $result) = @_; die ref $result ? "Fault Code: " . $result->faultcode . "\n" . "Fault String: " . $result->faultstring . "\n" : $soap->transport->status, "\n"; }); my $params = { foo => 'bar', biz => 'baz'}; #my $data = SOAP::Data->name($params); #my $serial = $client->serializer; #my $xml = $serial->envelope($data); #print Dumper $xml; #my $result = $client->my_api_method($params); my $result = $client->call('my_api_method' => $params);

I've figured out that $client->my_api_method(\%params) is the same as $client->call('my_api_method' => \%params)

When running with trace, it looks like SOAP::Serializer is getting a hash, but when I call $serial->envelope($data) I get an error that it's "Wrong type of envelope (SOAP::Data=HASH(0x8feb78)) for SOAP call". (Of course all the docs point to the SOAP::Serialize docs say that it's used by SOAP::Lite and all the SOAP ::Lite docs say to see SOAP::Serialize... :/ http://search.cpan.org/~kbrown/SOAP-0.28/lib/SOAP/Serializer.pm I've looked at the code for SOAP::Serializer, I'm not convinced it's what's building the XML.)

What modules used by SOAP::Lite actually generate the XML here? I can generate a SOAP::Data hash, but then what do I do with it? I know I can pass it to $client->call so something behind that is generating the xml.

Thanks for the assistance.

  • Comment on [SOAP::Lite] what happens when I call $client->call('Method', \%params)?
  • Download Code

Replies are listed 'Best First'.
Re: [SOAP::Lite] what happens when I call $client->call('Method', \%params)?
by Anonymous Monk on Jan 29, 2015 at 02:10 UTC

      Hello

      Thanks for trying to help again. I did read the source and I'm not sure I really understand what's going on so was hoping someone could help explain what's actually going on. Where is the actual XML generated?

      I'm assuming it's in this block of code:

      my $response = $self->transport->send_receive( context => $self, # this is provided for context endpoint => $self->endpoint, action => scalar($self->on_action->($serializer->uriformetho +d($_[0]))), # leave only parameters so we can later update them if + required envelope => $serializer->envelope(method => shift, @_), encoding => $serializer->encoding, parts => @{$self->packager->parts} ? $self->packager->parts + : undef, );

      because the very next line appears to deal with a response:

      return $response if $self->outputxml;

      Is it really as simple as prefixing my '->envelope' call with '->envelope(method =>'?... that would be really nice.

      EDIT: Holy Crap Yes!!!! that's all I had to do!