Posted on 2008-12-07 10:52:15-08 by gjongerh
Missing attachment from server to client
When i use the example for sending attachments form the cpan documentation I do receive a attachment and can save the file to disk. Unfortunately the is not sending a attachment back. here is the trace form the server program. Is there something more needed to return a attachment from the server to the client?
SOAP::Transport::new: () SOAP::Serializer::new: () SOAP::Deserializer::new: () SOAP::Parser::new: () SOAP::Server::new: () SOAP::Transport::HTTP::Server::new: () SOAP::Transport::HTTP::Daemon::new: () Contact to SOAP server at http://test02:81/ SOAP::Server::handle: () SOAP::Deserializer::deserialize: () SOAP::Parser::decode: () Use of uninitialized value $id in substitution (s///) at /usr/lib/perl5/site_perl/5.10.0/SOAP/Lite. +pm line 1995. SOAP::SOM::new: () SOAP::Data::new: () SOAP::Data::DESTROY: () (eval): ARRAY(0x8b37874) Gerard test: file.zip SOAP::Data::new: () SOAP::Server::handle: MIME::Entity=HASH(0x8b39bcc) SOAP::Data=HASH(0x8b20064) SOAP::Serializer::envelope: () SOAP::Serializer::envelope: hiResponse SOAP::Data=HASH(0x8b20064) SOAP::Data::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::Data::new: () SOAP::SOM::DESTROY: ()
<b>The server program:</b> #!/usr/bin/perl -w use SOAP::Lite +trace => [qw(all debug result)]; use SOAP::Transport::HTTP; use SOAP::Lite::Packager; use MIME::Entity; my $daemon = SOAP::Transport::HTTP::Daemon -> new (LocalPort => 81) ->packager(SOAP::Lite::Packager::MIME->new) -> dispatch_to('Attach') ; print "Contact to SOAP server at ", $daemon->url, "\n"; $daemon->handle; BEGIN { package Attach; use vars qw(@ISA); @ISA = qw(Exporter SOAP::Server::Parameters); use SOAP::Lite; use SOAP::Lite::Packager; sub hi { my $self = shift; my $envelope = pop; # read attachments foreach my $part (@{$envelope->parts}) { print "Gerard test: " . $part->head->mime_attr("content-type.name") . "\n"; $ filename = ">" . "/tmp/" . $part->head->mime_attr('content-type.name'); open FH, $filename; binmode( FH); $io = $part->open( "r"); binmode( $io); print FH $b while( read( $io, $b, 1024)); close FH; close $io; } my $ent = build MIME::Entity Type => "application/zip", Path => "/tmp/file.zip", Filename => "file.zip", Disposition => "attachment"; return $ent, SOAP::Data->name('response' => "hello, Gerard Jongerhuis"); } } # end of BEGIN 1; <b>client program</b> #!/usr/bin/perl -w use SOAP::Lite; use SOAP::Lite::Packager; use MIME::Entity; my $ent = build MIME::Entity Type => "application/zip", Path => "file.zip", Filename => "file.zip", Disposition => "attachment"; $server = SOAP::Lite -> uri("http://localhost/Attach") #-> proxy("http://localhost/cgi-bin/perl/test_attach.pl") -> proxy("http://localhost:81") -> packager(SOAP::Lite::Packager::MIME->new) -> parts([ $ent ]) ; $call = $server->call('hi', []); die $call->faultstring if $call->fault; print $call->result. "\n"; if ($call->is_multipart()) { print "Bijlagen gevonden. (response is multipart!)\n"; foreach my $part (@{$call->parts}) { print "attachment found! (".ref($part).")\n"; print "contents => ".$part->stringify."\n"; print "filename: " . $part->head->mime_attr("content-type.name") . "\n"; } }
Direct Responses: 10910 | Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.