Loading ...
Sorry, an error occurred while loading the content.

Re: [soaplite] Idiots Guide to Mime Attachments and SOAPLight

Expand Messages
  • Duncan Cameron
    ... For your purposes, if you do not want to pass any data from the client to the server then you can leave that out. ... It looks like the inheritance from
    Message 1 of 2 , Nov 11, 2004
      At 2004-11-11, 06:44:01 Will Fawcett <nailism23@...> wrote:

      >To Start, I am a newbie to SOAP WSDL and Sadly even OO-Perl, So I
      >realize I am at a extreme disadvantage. But I really need to get a
      >Soap Client Sending and Attachment to a server. Sadly I can't find
      >any working examples to help me out. Majordojo is a great resource
      >but I fear that it expects a higher understanding of Perl and SOAP
      >than I currently possess. I have some very basic questions, please
      >don't laugh. I really just want to learn.
      >#!/usr/bin/perl -w
      >use SOAP::Lite;
      >use MIME::Entity;
      >$namespace = "my namespace";
      >$uriLoc = "script location";
      >my $ent = build MIME::Entity
      > Type => "image/gif",
      > Encoding => "base64",
      > Path => "blah.gif",
      > Filename => "blah.gif",
      > Disposition => "attachment";
      >my $som = SOAP::Lite
      > ->readable(1)
      > ->uri($namespace)
      > ->parts([$ent])
      > ->proxy($uriLoc)
      > ->AttachmentHandler(SOAP::Data->name("foo" => "bar"));
      >As you can see it is exactly the code found on Brynes Website, my
      >question is that what is the reason for that last line "SOAP::Data-
      >>name("foo"=>"bar)); ?? I know that it will serialize as
      ><foo>bar</foo> but what do I need on the server to accept that, and
      >why can't I just leave it out?
      For your purposes, if you do not want to pass any data from the client
      to the server then you can leave that out.

      >My Server currently looks like this:
      >#!/usr/bin/perl -w
      >use SOAP::Transport::HTTP;
      >use MIME::Parser;
      >print $MIME::Parser::VERSION;
      > -> dispatch_to('lifestyle')
      > -> handle;
      >package lifestyle;
      > use SOAP::Lite;
      > use MIME::Entity;
      > use vars qw(@ISA);
      > @ISA= qw(SOAP::Server::Parameters);
      >sub AttachmentHandler{
      > my $self = shift; # this is the package declaration aka lifestyle
      > my $envelope = pop;#this is the value of the SOAP::Data::Name
      > my $STRING = $envelope->valueof(`[1]');
      > print STDERR $STRING;
      >Presently I get an error:
      >soap:Server, Can't locate object method "valueof" via package "bar"
      >(perhaps you forgot to load "bar"?)
      >at /home/demo/bin/SendBinData.cgi line 20.
      It looks like the inheritance from SOAP::Server::Parameters isn't
      taking effect because the lifestyle package @ISA has not been assigned
      to - remember that it is a run-time assignment, not compile-time.

      Three choices

      1) move the lifestyle package to a separate source file and change the
      dispatch_to() to include the directory

      2) move the lifestyle code to the start of this file, and then switch
      back to the main package

      package lifestyle;


      package main;


      3) wrap the lifestyle package in a BEGIN block so that it gets executed

      But you don't really want to be looking at the envelope anyway. The
      attachments are automatically decoded for you.

      The server code is as simple as this:

      use strict;
      use SOAP::Transport::HTTP;

      my $packager = SOAP::Packager::MIME->new;

      -> dispatch_to('.')
      -> handle;

      put your application code in its own source file


      use strict;
      package lifestyle;

      use SOAP::Lite;
      use vars qw(@ISA);
      @ISA= qw(SOAP::Server::Parameters);

      sub AttachmentHandler{
      my $self = shift;
      my $envelope = pop;
      foreach my $part (@{$envelope->parts}) {
      print STDERR "attachment found! (".ref($part).")\n";
      return "OK";

      Each attachment and the soap envelope will now be saved automatically
      in the Attachments subdirectory.

      Try this and see how you get on.

    Your message has been successfully submitted and would be delivered to recipients shortly.