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

I have been using SOAP::Lite for awhile, but I now have the requirement of needing to send an attachment to the client. I have tried using code from the SOAP::Lite perldoc like so:
#!/usr/bin/perl package Attachment; use SOAP::Lite; use MIME::Entity; use strict; use vars qw(@ISA); @ISA = qw(SOAP::Server::Parameters); sub someMethod { my $self = shift; my $envelope = pop; my $ent; $ent = build MIME::Entity Id => "<1234>", Type => "image/gif", Encoding => "base64", Path => "some.gif", Filename => "goit.gif", Disposition => "attachment"; return $ent,SOAP::Data->name( "foo" => "bar" ),$ent; } 1;
On the client side, I have tried
$result = SOAP::Lite->uri($SOME_NAMESPACE) ->proxy($SOME_HOST) ->s +omeMethod(); print "Parts:\n"; foreach my $part ( ${ $result->parts } ) { print $part->stringify; }
which results in "Not a SCALAR reference".
I've also tried using use SOAP::Lite +trace => 'debug'; to see if the binary is coming back, but nothing.
What am I missing?

Replies are listed 'Best First'.
Re: SOAP::Lite Server Attachment
by gellyfish (Monsignor) on Aug 20, 2006 at 09:58 UTC

    I assume you are using either version 0.68 or 0.69 of SOAP::Lite, it appears that in these versions the specific line that does the MIME packaging is commented out at line 1554 in Lite.pm:

    # Sometimes SOAP::Serializer is invoked statically when there is no + context. # So first check to see if a context exists. # TODO - a context needs to be initialized by a constructor? if ($self->context && $self->context->packager->parts) { # TODO - this needs to be called! Calling it though wraps the payloa +d twice! # return $self->context->packager->package($self->xmlize($encoded)) +; }
    YOu could try un-commenting the line but I think there would be more work to be done to make it work properly. Word has it that earlier versions do work however.

    /J\

      I tried 0.67, 0.66, and 0.65_6 with no luck.
      Unfortunately, my perl knowledge isn't all that great. I lack the knowledge of SOAP/XML inners as well. (But that's the idea of a module, to keep you from the details.)
      Thanks for confirming that it isn't something wrong I'm doing. ;)
Re: SOAP::Lite Server Attachment
by duckyd (Hermit) on Aug 18, 2006 at 22:20 UTC
    It looks like you expect $result->parts to return an array reference, but you're treating it like a scalar reference. Maybe you want:
    foreach my $part ( @{ $result->parts } ){
    You might consider using Data::Dumper to dump $result (or just $result->parts).

    On the server side, why are you returning $ent,SOAP::Data->(...),$ent ? From the POD it looks like that should be

    return SOAP::Data->name(...),$ent;
      I see it was $ in the SOAP::Lite pod client access, but correctly @ in the server attachment access.
      I forgot I tried changing the return, but makes no difference. Using:
      return SOAP::Data->name(...),$ent;
      doesn't return the expected MIME attachment either.