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;
}
}