Retrieving an Unreferenced Attachment
Let’s look at the WSDL binding for a method getDocuments that returns a MIME attachment:
 
<binding name="DocumentManagerBinding" type="tns:DocumentManagerPortType">
<soap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>
</binding>
Note that, unlike the addDocument example above, this binding does not list a mime:content element and does not reference a part. This is called an “unreferenced attachment”, while the example for addDocument showcases a referenced attachment where the MIME elements directly reference the part.
Here’s the code that is provided for the client operation getDocuments() in the sample client implementation DocumentManagerPortClient.cpp. Recall that the getDocuments method returns a MIME document that contains a list of document names and keys, and a set of unreferenced MIME attachments.
 
void invoke_getDocuments(DocumentManagerBindingProxy& proxy)
{
tns::Documents documents_ret; //1
rwsf::CallInfo callInfo;
 
try {
documents_ret = proxy.getDocuments(callInfo); //2
typedef tns::Documents::ListVector vector_type;
vector_type items = documents_ret.getListVector();
for (vector_type::const_iterator it = items.begin(); it != //3
items.end(); ++it) {
std::string name = (*it).getDocumentName();
std::cout << "Received document: " << name << std::endl;
std::string url = (*it).getDocumentRef(); //4
std::string uid(url);
rwsf::MessageAttachment att = //5
callInfo.getResponseAttachment(uid);
if (att.getUniqueId() == uid) { //6
std::string contents = att.getPayload();
std::cout << " contents= " << contents << std::endl;
}
else {
std::cout << " No contents were found." << std::endl;
}
}
} catch(const rwsf::SoapFaultException& e) {
std::cout << "Fault Code: " << e.getFault().getFaultcode().asString()
<< std::endl;
std::cout << "Fault String: " << e.getFault().getFaultstring() << std::endl;
}
}
//1 Note that the response is an instance of tns::Documents, which is defined in the WSDL as an instance of a tns::DocumentPairList and is therefore generated as a std::vector of tns::DocumentPair elements.
//2 Make the actual client call to the web service operation. Returns the DocumentPairList containing the documents.
//3 Begins iteration over all items in the Document list, and prints to standard out that the document has been received.
//4 Here, we extract the Content-ID for the associated attachment. Remember that the variable documentRef is of type tns:swaRef, and so represents any associated message attachment using a URI as a reference.
//5 Retrieves the message attachment as an instance of rwsf::MessageAttachment, based on the URL specified in the SOAP message. Note that the attachment is returned using rwsf::CallInfo’s method getResponseAttachment based on its Content-ID.
//6 Retrieves the attachment if it’s found.