WebSphere Web Services Client for C++ Operating Systems: Linux, Solaris

Attachments

You can use Web Services Client for C++ to send attachments. An attachment is data that is attached to a message on the wire, separately from the SOAP envelope. Attachments are often used for sending large files or images. You can create an attachment by describing it in the WSDL used to generate client stubs, or by using the dynamic client API.

Web Services Client for C++ provides the following support for attachments:

When you are using attachments, the message that is sent is a MIME message, which contains a SOAP envelope. When you are not using attachments, the message that is sent is a SOAP envelope.

Web Services Client for C++ supports attachments that can be referred to from the SOAP body. Such attachments are called referenced attachments. Referenced attachments are described in the WSDL used to generate theclient stubs , and appear as parameters on web service methods on the generated stubs. Web Services Client for C++ does not support attachments that are not referenced from the SOAP body.

A MIME message is made up of MIME parts, which are separated by a MIME boundary. The root part of a MIME message contains the SOAP envelope, and other, non-root, parts contain attachments. The HTTP headers contain information about the whole MIME message. Each MIME part contains MIME headers, one of which must be the Content-Id. The attachment reference that is put into the SOAP body contains the Content-Id of the attachment that is being referred to.

An attachment is represented in C++ as an ISoapAttachment, which you create using either Stub::createSoapAttachment (see Using generated stubs) or Call::createSoapAttachment (see Using the dynamic client API). Methods on ISoapAttachment allow applications to set MIME headers and to set the attachment body. The attachment body is passed to ISoapAttachment::setBody as binary data, as an xsd__base64Binary, because Web Services Client for C++ only supports base64 encoding. An attachment reference may have attributes. Some MIME headers on MIME parts have the following default values:

Content-Type: text/plain
Content-Transfer-Encoding: base64

Web Services Client for C++ also generates a Content-Id for each attachment. The Content-Id is unique within the MIME message. All the MIME headers can be changed using ISoapAttachment::addHeader.

Using generated stubs

Referenced attachments are described in the WSDL used to generate the client stubs. The following example shows part of a WSDL that describes an image attachment.

<wsdl:types>
  <schema xmlns:tns2="http://xml.apache.org/xml-soap" ...>
   <import namespace="http://xml.apache.org/xml-soap"/>
   <element name="put">
    <complexType>
     <sequence>
      <element name="arg1" type="tns2:Image"/>
     </sequence>
    </complexType>
   </element>
  </schema>
 </wsdl:types>

Web Services Client for C++ represents the types DataHandler, Image, and PlainText in the http://xml.apache.org/xml-soap namespace as attachments. If you ran the WSDL2Ws tool to generate a stub for this WSDL, this stub would contain a method that is passed a ISoapAttachment*.

Using the dynamic client API

You can also create an attachment using the dynamic client API. To do this, create an ISoapAttachment using Call::createSoapAttachment, configure it as required, and then add it as a referenced attachment using Call::addAttachmentParameter.

Related tasks
Creating client stubs

Concept topic

Terms of Use | Feedback

Last updated: 26 Oct 2005

© Copyright IBM Corporation 2005. All Rights Reserved.