ReadyAPI supports multiple ways to add attachments to your SOAP requests – from inlining the attachment file to using MTOM to make sure your attachments are sent in an efficient manner.
Attachments With Type Defined Automatically
ReadyAPI can analyze the schema and send the attachment with the appropriate type automatically. This way, you can attach your files both inline and by using MIME-like approaches such as SwaRef or MTOM.
When you attach a file, a unique ContentID will be assigned to it. You can then reference this ID from the node you plan to attach the file to and let ReadyAPI resolve the attachment automatically:
Attachment Type | The Attachment Should Be in | Assigned Type | Example |
---|---|---|---|
Inline |
The base64Binary or hexBinary data element. |
Content |
<xsd:element name="binaryData" type="xsd:base64Binary"> |
MTOM | A data element of some XMIME data type. |
XOP |
<xsd:element name="binaryData" type="xmime:base64Binary" |
SwaRef | The attachment is in the wsi:swaRef element. |
SWAREF | <xsd:element name="binaryData" type="wsi:swaRef" |
Attaching Files to Requests
To attach a file to a request by using its ContentID:
-
Open the Attachments panel and click Add Attachment.
-
Select the file you want to send. ReadyAPI will ask you whether you want to cache it in the request. Uncached attachments are read from the file directly each time the request is sent. Cached attachments are stored in the project and are not changed when you update the original file.
-
Specify
cid:<Sample.xml>
in the element you plan to attach the file to.
Now, when you send a request, ReadyAPI will analyze the schema definition for the element you attached and send the attachment with the appropriate type.
Sample Requests
Here are some examples of files attached to requests in different ways.
With Inline Attachment
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<sample:Attachment_Add xmlns:sample="http://schemas.xmlsoap.org/sample">
<sample:binaryData>iVBORw0KGgoAAAANSUhEUgAAAYcAAADnCAYAAAD1nZqQAAAAAXNSR0IArs...</sample:binaryData>
<sample:Attachment_Add>
</soapenv:Body>
</soapenv:Envelope>
With MTOM Attachment
------=_Part_0_777481056.1489136258868
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: 8bit
Content-ID: <[email protected]>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xm="http://www.w3.org/2005/05/xmlmime">
<soapenv:Header/>
<soapenv:Body>
<Attachment_Add>
<binaryData><inc:Include href="cid:sample.gif" xmlns:inc="http://www.w3.org/2004/08/xop/include"/></binaryData>
<Attachment_Add>
</soapenv:Body>
</soapenv:Envelope>
------=_Part_0_777481056.1489136258868
Content-Type: image/gif; name=sample.gif
Content-Transfer-Encoding: binary
Content-ID: <sample.gif>
Content-Disposition: attachment; name="sample.gif"; filename="sample.gif"
... binary image data ...
------=_Part_0_777481056.1489136258868
With SwaRef Attachments
Content-Type: Multipart/Related; start-info="text/xml"; type="application/xop+xml";
boundary="----=_Part_0_65289531.654616813"
Content-Length: 1193
SOAPAction: ""
------=_Part_1_32550604.1118953563502
Content-Type: application/xop+xml; type="text/xml"; charset=utf-8
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<claimForm>cid:Sample.gif</claimForm>
</soapenv:Body>
</soapenv:Envelope>
------=_Part_1_32550604.1118953563502
Attachments Specified With File Path
If your request has base64Binary
or hexBinary
data elements, you can add the attachment to it by specifying the path to the file. To do this:
-
Set the Enable Inline Files request property to
true
. -
Add the reference to the file in the element you need it in, for example:
<sample:binaryData>file:C:/Image.png</sample:binaryData>
When you run the request, ReadyAPI will get the specified file and send it to the server.
Attachments Added Directly to Request
Instead of attaching the file to the request and letting ReadyAPI Test handle the transformation, you can convert the file to the Base64 encoding and insert it manually to where you need it. To do this, right-click the place where you need the attachment to be and select Insert file as Base64. Then, select the file to be inserted to a request.
Attachments not Specified in Service Definition
If you need to send an attachment not specified in the service definition, add it to the Attachments panel and select <anonymous>
in the Part column.