SOAP Attachments

Transporting binary data (such as images, artibrary files, etc), via SOAP can be inefficient, as the data has be base64 encodeded and decoded, and is contained within the SOAP message itself, which can increase the XML parsing overhead. To alleviate this, you can transport this data as attachments, so that it exists outside of the SOAP message, and is not base64 encoded & decoded.

PocketSOAP supports attachments using either SOAP with Attachments or DIME

The SOAP with Attachments suport has been sucessfully tested against

The DIME support has been sucessfully tested against

Making request's that include attachments

The Attachments Manager object is the key point to making requests that include attachments, you use this object, to create attachments in the request, build and send the request complete with attachments, and to parse attachments contained in the response. Here's a walk through of using the attachments manager to make a call with attachments.

You need to indicate if you want to do DIME or MIME based attachments before you add any attachments.
set mgr = CreateObject("pocketSOAP.Attachments")
mgr.Format = formatDime
This creates a new attachment in the request collection, and returns it.
set att = mgr.Request.Create ("c:\image.gif", tnfMediaType, "image/gif")
Typically you assign the URI of the attachment to the href attribute of a parameter in the SOAP message
set n = e.parameters.create ("attachment", empty )
n.href = att.Uri
Create and configure the HTTP transport object as normal, then set the transport property on the attachment objects to the transport object
set t = CreateObject("pocketSOAP.HTTPTransport")
t.SetProxy "localhost", 7070
t.Soapaction = ""
set mgr.Transport = t 
Now we send through the attachments manager, rather than direct to the transport, the attachments manager will package everything up in the required format and send it to the underlying transport object created earlier.
mgr.Send "", e.Serialize
Again, for the parsing end, the attachments manager is shimmed between the parser and the transport, so you call parse specifying the attachments manager.
e.parse mgr
Finally, you use the href property on the node to get the URI of the response attachment, and then look for it in the response attachments collection
href = e.parameters.Item(0).href
set theAttachment = mgr.response.find(href)

if theAttachment.Location = attInMemory then
	theAttachment.Save "c:\att.gif" 
end if
msgbox "attachment saved as " & theAttachment.Body


Copyright © Simon Fell, 2002-2004. All rights reserved.