Trying to provide a web service capable of sending files to a client on request, I run into the following problem:
On the server side, the service is written in Java, using Axis 1 v1.4.1 (I know, it's obsolete, but it's a legacy application which I'm supposed to extend, and the effort involved in migrating to something more up-to-date, like Axis 2, should be avoided if in any way possible). There, I do something like this (note that this snippet omits things like security checking and other non-essentials for brevity):
public void downloadFile(final String filename) throws SOAPException {
MessageContext mc = MessageContext.getCurrentContext();
Message msg = mc.getResponseMessage();
Attachments atts = msg.getAttachmentsImpl();
atts.setSendType(Attachments.SEND_TYPE_MTOM);
AttachmentPart ap;
try {
ap = (AttachmentPart) atts.createAttachmentPart();
} catch (AxisFault e) {
throw new SOAPException(e);
}
DataHandler dh = new DataHandler(new DataSource() {
public String getContentType() {
return "application/octet-stream";
}
public InputStream getInputStream() throws IOException {
return new FileInputStream(filename);
}
public String getName() {
return filename;
}
public OutputStream getOutputStream() throws IOException {
return null;
}
});
ap.setDataHandler(dh);
try {
ap.setContent(dh.getContent(), dh.getContentType());
} catch (IOException e) {
throw new SOAPException(e);
}
msg.addAttachmentPart(ap);
}
Previously, this service used DIME to transmit attachments, but that protocol seems to have only very limited support and the goal is to increase interoperability to a wider range of platforms, hence the switch to MTOM.
Now, on the client (.NET) side, with WSE 2 it was possible to simply access the Attachments collection of the service's ResponseSoapContext. Since WSE 2 does not support MTOM, an upgrade to WSE 3 was necessary. This, however, somehow expects the attachment to be returned as a byte array by the web service method - and there lies the problem:
- The java implementation of the service method above has a void return type, so when I auto-generate the WSDL for it, the WSDL also specifies a void return type, and thus when adding a web reference on the client side, the generated method also returns void; not a byte array.
- On the other hand, if I try to specify a byte array response type in the WSDL, generate the server code stub and try to implement the method, I don't have a byte array to return (I don't think it would be a good idea to actually return the bytes of the file; I did not try it but I believe Axis would attempt to serialize it into the response stream defeating the purpose of using an attachment...).
Is there any way to bridge this gap?