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

Any examples of SOAP attachments?

Expand Messages
  • harbica
    I have a web service (in Java using JAXRPC) that accepts a file upload. My java client is working just fine. I can t, however, figure out how to get
    Message 1 of 2 , Dec 22, 2005
    • 0 Attachment
      I have a web service (in Java using JAXRPC) that accepts a file
      upload. My java client is working just fine.

      I can't, however, figure out how to get SOAP::Lite to upload the file
      as a SOAP attachment.

      Does anyone have an example of uploading a file as a SOAP attachment
      to a webservice?

      Thanks!
      Andy
    • harbica
      Got it working! Thanks for the pointer Byrne (BTW, if you search for attachments on your site it doesn t turn up anything... Google found it). I found some
      Message 2 of 2 , Jan 2, 2006
      • 0 Attachment
        Got it working! Thanks for the pointer Byrne (BTW, if you search for
        "attachments" on your site it doesn't turn up anything... Google found
        it). I found some stuff to help out.

        Here's the snippet that works for me:
        # Build a MIME attachment
        my $name = $file; $name =~ s/.*\/([^\/]*)$/$1/;
        my $ent = MIME::Entity->build(Type => "application/octet-stream",
        Encoding => "8bit",
        Path => $file,
        Disposition => "attachment",
        Id => $name,
        Mode => 1);
        $svc->parts(($ent));

        die "Failed to upload file" if $svc->uploadFile(
        SOAP::Data->type("datahandler")
        ->attr({'href' => "cid:$name"})) < 0;

        My JAX-RPC endpoint looks like this:
        public long uploadFile(DataHandler dh) throws RemoteException;

        Working with a TCP proxy/snooper (I still use
        org.apache.soap.util.net.TcpTunnelGui) I culled enough information to
        get it going. So here's the lessons learned:

        1. Use MIME::Entity to build up the message

        2. You must have SOAP::Lite .60 or greater... The parts() API
        doesn't exist in other versions... Looks like there was a module
        SOAP::MIME that you could use with pre .60 versions but I didn't try
        that out.

        3. You've gotta add a maptype for datahandler:
        $svc->maptype({datahandler => 'http://java.sun.com/jax-rpc-ri/
        internal});

        4. When you build the MIME::Entity be sure to include the "Id"...
        It gets added as the Content-Id header which JAXRPC expects.

        5. When you call the API be sure to pass a "datahandler" with an
        href to the Content-Id that you added.

        Andy

        On Dec 22, 2005, at 12:49 PM, Byrne Reese wrote:

        > http://www.majordojo.com/soaplite/
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.