views:

466

answers:

1

I'm currently modifying a document literal SOAP service for a business app which transfers data about customers backwards and forwards.

A new requirement to transfer scanned document images has just been identified. The problem I have is that the proprietary language I use does not support SOAP attachments.

The images being transferred can be anything upto 32KB.

The only solution I can think of is to base64 encode the image, and pass it through as an element of the XML document.

This feels like a really bad idea, but I just can't think of anything better.

Any ideas?

EDIT: I forgot to mention that the image isn't held remotely in a file system, it is stored in an Oracle database, which I do not have the ability to connect directly to,

+3  A: 

If you're using XML as a data transfer mechanism, you have to encode the image in some way. The reason is that XML is a text format, and an XML processor will attempt to decode binary data as if it's text (more specifically, as if it's UTF-8 unless you specify a different encoding). Moreover, XML explicitly disallows several characters (most ASCII non-printables for XML 1.0, \u0000 for XML 1.1), so you'll corrupt your data if you just dump the image data into (say) a CDATA section.

Edit: XML Schema defines a "base64Binary" type, so you should be able to define your WSDL appropriately (assuming that you're using an automated marshaller). At the least, you should use an "xsi:type" attribute on the element containing your encoded content.

kdgregory
This works for me!
kingmunkyman
base64Binary and hexBinary both work. Good answer!
Cassy