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

OK, so there is some SOAP service on http://webservices.seek.com.au/marketsegment.asmx, if you go here and enter eg. "Main" into the inputbox and submit the form you can see the result. After wasting lots of time (as is to be expected with SOAP) I am able to send a request accepted by the service (ab)using SOAP::Lite and get this load of bull^B^B^B^BXML back. The test output from use SOAP::Lite +trace => [ all, -transport ]; looks correct, the print Dumper($som) looks about right as well. Or at least it seems to contain the data it's supposed to.

But print Dumper($som->result) prints just

$VAR1 = { 'SpecificClassification' => { 'list' => { 'listItem' => '' } } };
Very helpfull, isn't it?

Here's the code:

# MarketSegment.pm package MarketSeg; # -- generated by SOAP::Lite (v0.60) for Perl -- soaplite.com -- Copyr +ight (C) 2000-2001 Paul Kulchenko -- # -- generated from http://webservices.seek.com.au/marketsegment.asmx? +wsdl [Tue Mar 8 15:31:24 2005] my %methods = ( GetMarketClassifiers => { endpoint => 'http://webservices.seek.com.au/marketsegment.asmx', soapaction => 'http://webservices.seek.com.au/GetMarketClassifiers +', uri => '', parameters => [ SOAP::Data->new(name => 'marketSegment', type => '', attr => {}) +, ], }, ); use SOAP::Lite; use Exporter; use Carp (); use Data::Dumper; #use SOAP::Lite +trace => [ all, -transport ]; use vars qw(@ISA $AUTOLOAD @EXPORT_OK %EXPORT_TAGS); @ISA = qw(Exporter SOAP::Lite); @EXPORT_OK = (keys %methods); %EXPORT_TAGS = ('all' => [@EXPORT_OK]); no strict 'refs'; for my $method (@EXPORT_OK) { my %method = %{$methods{$method}}; *$method = sub { my $self = UNIVERSAL::isa($_[0] => __PACKAGE__) ? ref $_[0] ? shift # OBJECT # CLASS, either get self or create new and assign to + self : (shift->self || __PACKAGE__->self(__PACKAGE__->new +)) # function call, either get self or create new and assign to sel +f : (__PACKAGE__->self || __PACKAGE__->self(__PACKAGE__->new)); $self->proxy($method{endpoint} || Carp::croak "No server address ( +proxy) specified") unless $self->proxy; my @templates = @{$method{parameters}}; my $som = $self -> endpoint($method{endpoint}) -> uri($method{uri}) -> on_action(sub{qq!"$method{soapaction}"!}) -> readable(1) # -> call($method => map {@templates ? shift(@templates)->value($ +_) : $_} @_); -> call( SOAP::Data->name($method)->attr({xmlns => 'http://webse +rvices.seek.com.au'}) => map {@templates ? shift(@templates)->value($ +_) : $_} @_); #print "=====================SOM====================\n",Dumper($som)," +\n========================/SOM=============\n"; #print "=====================freeform====================\n",Dumper($s +om->freeform),"\n========================/freeform=============\n"; if ($som->fault) { die "The unclef***ing SOAP failed again, bastard!\n" . $som->f +aultstring; } UNIVERSAL::isa($som => 'SOAP::SOM') ? wantarray ? $som->paramsall +: $som->result : $som; } } sub AUTOLOAD { my $method = substr($AUTOLOAD, rindex($AUTOLOAD, '::') + 2); return if $method eq 'DESTROY'; die "Unrecognized method '$method'. List of available method(s): @EX +PORT_OK\n"; } 1; #test.pl use MarketSeg; $soap = new MarketSeg; my $xml = MarketSeg::GetMarketClassifiers("Main"); use Data::Dumper; print Dumper($xml);

So what am I supposed to use to get my dirty hands at the data? (Converting the misdesigned mess to something usefull is gonna be yet another fun.)

P.S.: I admit I did not sacrifice the chicken yet.

Jenda
XML sucks. Badly. SOAP, on the other hand, is the most powerfull vacuum pump ever invented.

Replies are listed 'Best First'.
Re: SOAP::Lite? Erm, what the (censored) is the $som->result supposed to return?
by gellyfish (Monsignor) on Apr 27, 2005 at 14:40 UTC

    If you look at the WSDL you will see that the response message is defined like:

    <s:element name="GetMarketClassifiersResponse"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="GetMarketClas +sifiersResult"> <s:complexType mixed="true"> <s:sequence> <s:any /> </s:sequence> </s:complexType> </s:element> </s:sequence> </s:complexType> </s:element>
    The problem with this is that the actual payload is therefore the <s:any /> - that is to say the designers punted on the definition and opted to say "we're going to return some XML of some sort" - it appears from the XML below that this is being generated from another system and not by the .NET serialization. This is not very useful and the stub created by stubmaker.pl is not going to deal with it well as it stands. Because this is an ASP.NET web service one is able to access it, for nstance, via an HTTP GET - you can see that it returns something like:
    <SpecificClassification xmlns="http://seek.com.au/SpecificClassificati +on.xsd"> <list id="list-1" value="Location" multiSelect="false"> <listItem id="listItem-1000" value="Sydney" linking="listItem-2819 + listItem-2820 listItem-2821 listItem-2822 listItem-2835 listItem-283 +6 " legacyID="listItem-1000"> </listItem> </list> </SpecificClassification>
    (I've removed most of the records for clarity.)

    You could quite easily use LWP::UserAgent to retrieve the data as above and the use (e.g.) XML::Simple to access the data or you should be able to use SOAP::SOM directly, however there appears to be a bug somewhere that is stopping it from getting at the attributes, so I think that you probably want to use my first suggestion until it gets fixed.

    You can access the attributes odf the listItem elements with something like:

    use SOAP::Lite ; + my $client = SOAP::Lite ->readable(1) ->uri('http://webservices.seek.com.au') ->autotype(0) ->on_action(sub { join '/', @_ }) ->proxy('http://webservices.seek.com.au/marketsegment.a +smx'); $som = $client->GetMarketClassifiers(SOAP::Data->name('mark +etSegment','Main')->uri('http://webservices.seek.com.au')); + my $foo = $som->match('//GetMarketClassifiersResponse/SpecificClassifi +cation/list/'); + foreach my $item ($foo->dataof('//listItem/')) { print $item->attr->{id},"\n"; }
    - it's just a matter of finding the right combination of SOAP::SOM and SOAP::Data munging.

    update: It appears the bug was in my brain.

    /J\

      I guess you are right, in this case LWP::Simple+XML::Simple will be much better. Until SEEK decides to break it.
      This whole XML infested world drives me crazy.

      Jenda
      XML sucks. Badly. SOAP on the other hand is the most powerfull vacuum pump ever invented.

Re: SOAP::Lite? Erm, what the (censored) is the $som->result supposed to return?
by Jenda (Abbot) on Apr 27, 2005 at 14:03 UTC
    sub SOAP::SOM::childof { my $self = shift; local $self->{_current} = $self->{_current}; $self->match(shift) if @_; return wantarray ? map {o_child($_)} @{$self->{_current}} : @{$self->{_current}} ? o_child($self->{_current}- +>[0]) : undef; } print Dumper($som->childof('/Envelope/Body/[1]/[1]'));
    Seems to give me the data. Am I really supposed to dig this low?

    Jenda
    XML sucks. Badly. SOAP on the other hand is the most powerfull vacuum pump ever invented.