SOAP::MIME Perl Module
SOAP::MIME is a Perl Module that allows for payloads to be attached to SOAP messages via the MIME format. SOAP::MIME was originally developed as a separate Perl Module for SOAP::Lite 0.55. It has since been folded into the core of SOAP::Lite and is no longer necessary if you are using a recent version of SOAP::Lite. This page is maintained for archival purposes only. All SOAP::MIME users should upgrade to the latest stable version of SOAP::Lite.
Downloads
- SOAP-MIME-0.55.tar.gz
- SOAP-MIME-0.55-2.tar.gz
- SOAP-MIME-0.55-3.tar.gz
- SOAP-MIME-0.55-4.tar.gz
- SOAP-MIME-0.55-5.tar.gz
- SOAP-MIME-0.55-6.tar.gz
- SOAP-MIME-0.55-7.tar.gz
Shortcuts
Code Samples
Sending Attachments
Receiving Attachments
Sending just one attachment
#!/usr/bin/perl
use SOAP::Lite +trace => qw(debug);
use SOAP::MIME;
use MIME::Entity;
my $ent = build MIME::Entity
Type => "image/gif",
Encoding => "base64",
Path => "somefile.gif",
Filename => "saveme.gif",
Disposition => "attachment";
my @parts = ($ent);
my $som = SOAP::Lite
->readable(1)
->uri($SOME_NAMESPACE)
->parts(@parts)
->proxy($SOME_HOST)
->some_method(SOAP::Data->name("foo" => "bar"));</tt></pre>
Sending more than one attachment
#!/usr/bin/perl
use SOAP::Lite +trace => qw(debug);
use SOAP::MIME;
use MIME::Entity;
my $ent1 = build MIME::Entity
Type => "image/png",
Encoding => "base64",
Path => "attachments/reg-step1sm.png",
Filename => "reg_step1sm.png",
Disposition => "attachment";
my $ent2 = build MIME::Entity
Type => "text/xml",
Path => "attachments/some.xml",
Filename => "some.xml",
Disposition => "attachment";
push @attachments, $ent1;
push @attachments, $ent2;
my $som = SOAP::Lite
->readable(1)
->uri('http://webservices.imacination.com/distance/Distance.jws')
->parts(@attachments)
->proxy('http://webservices.imacination.com/distance/Distance.jws')
->getDistance(
SOAP::Data->name('fromZip' => 94610)->type('string'),
SOAP::Data->name('toZip' => 94105)->type('string')
);
Amazon Query MIME Variant
I wrote a SOAP Gateway to Amazon's REST interface a while ago... it was useful when Amazon had not caught on to SOAP yet. It is somewhat obsolete now. However, I implemented a variant of the service to return a book catalog in an attachment as opposed to the body of the SOAP response. I figured I would post a link to the CGI here since it shows a more full featured Web service that uses MIME.
Printing a set of attachments
#!/usr/bin/perl
use SOAP::Lite;
use SOAP::MIME;
my $soap = SOAP::Lite
->readable(1)
->uri($NS)
->proxy($HOST);
my $som = $soap->foo();
foreach my $part (${$som->parts}) {
print $part->stringify;
}
Write a CGI Server that receives and returns attachments
#!/usr/bin/perl
use SOAP::Transport::HTTP;
use SOAP::MIME;
SOAP::Transport::HTTP::CGI
->dispatch_to('SOAP_MIME_Test')
->handle();
BEGIN {
package SOAP_MIME_Test;
use strict;
use vars qw(@ISA);
@ISA = qw(SOAP::Server::Parameters);
sub echo {
my $self = shift;
my $envelope = pop;
foreach my $part (@{$envelope->parts}) {
print STDERR "Attachments.cgi: attachment found! (".ref($$part).")\n";
}
print STDERR "envelope is of type: " . ref($envelope) . "\n";
my $STRING = $envelope->dataof("//echo/whatToEcho")
or die SOAP::Fault->faultcode("Client")
->faultstring("You must specify a string to echo")
->faultactor('urn:SOAP_MIME_Test#echo');
my $ent = build MIME::Entity
'Id' => "<1234>",
'Type' => "text/xml",
'Path' => "examples/attachments/some2.xml",
'Filename' => "some2.xml",
'Disposition' => "attachment";
return SOAP::Data->name("whatToEcho" => $STRING),$ent;
}
}
Documentation
SOAP::MIME - Patch to SOAP::Lite to add attachment support. This module allows Perl clients to both compose messages with attachments, and to parse messages with attachments.
SYNOPSIS
SOAP::Lite (http://www.soaplite.com/) is a SOAP Toolkit that allows users to create SOAP clients and services. As of July 15, 2002, MIME support in SOAP::Lite was minimal. It could parse MIME formatted messages, but the data contained in those attachments was "lost."
This Perl module, patches SOAP::Lite so that users can not only send MIME formatted messages, but also gain access to those MIME attachments that are returned in a response.
TODO/ChangeLog
For more detailed information regarding changes to this software, check the official CHANGE_LOG.
4/16/2003 - Bug fixes
3/18/2003 - Added server-side attachment support for HTTP transport layer
7/26/2002 - Reworked the parsing of the response to return an array
of MIME::Entity objects which enables to user to more fully
utilize the functionality contained within that module
7/15/2002 - Ability to process attachments on the server side has not yet
been tested.
6/12/2002 - Need to add ability to compose and send attachments.
FIXED on 7/15/2002</pre></P>
REFERENCE
SOAP::SOM::parts()
Used to retrieve MIME parts returned in a response. The subroutine
parts()returns a reference to an array of MIME::Entity objects parsed out of a message.SOAP::Lite::parts(ARRAY)
Used to specify an array of MIME::Entities. These entities will be attached to the SOAP message.
