Web Service Development Guide : PART IV Extending your Applications : Chapter 17 SOAP with Attachments : The SOAP with Attachments Specification
The SOAP with Attachments Specification
The specification Soap Messages With Attachments defines a multipart message format called a SOAP message package. A SOAP message package is constructed according to the following rules:
The SOAP header’s Content-Type element must be the multipart/related media type.
The SOAP message itself is carried in the root body part of the multipart/related structure, so the type parameter of the multipart/related media header must be text/xml.
MIME attachments are referenced inside the SOAP message body using SOAP references.
Referenced MIME attachments must contain either a matching Content-ID header or a matching Content-Location header.
The specification also recommends that the root part contain a Content-ID header, and that the multipart/related media header contain a matching start parameter. This permits more robust error detection.
Figure 10 – SOAP Message with Attachments
The code below shows a SOAP 1.1 message package that contains a SOAP message in the root part that references an attached base64-encoded GIF image:
 
MIME-Version: 1.0
Content-Type: multipart/related; boundary="MIME_Boundary";
type=text/xml; start="<contacts.xml@someCompany.com>"
 
--MIME_Boundary
Content-ID: <contacts.xml@someCompany.com>
Content-Type: text/xml; charset=us-ascii
 
<SOAP-ENV:Envelope xmlns:SOAP-ENV=
"http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<getName>
<name>SomeCompany</name>
...
<photo href="cid:logo.gif@someCompany.com"/>
</getName>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
--MIME_Boundary
Content-ID: <logo.gif@someCompany.com>
Content-Type: image/gif
Content-Transfer-Encoding: base64
.... base64 encoded gif data
 
--MIME_Boundary--
In this example, the element in the SOAP message
 
<photo href="cid:logo.gif@someCompany.com"/>
references the attached image with the corresponding Content-ID header.
The sections that follow describe how to send and receive SOAP messages with MIME attachments over HTTP using HydraExpress. These sections assume you are familiar with the basic steps for using HydraExpress to generate code and develop Web services.